Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / putfence1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Put with Fence";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count; 
20     MPI_Comm      comm;
21     MPI_Win       win;
22     MPI_Aint      extent;
23     MTestDatatype sendtype, recvtype;
24
25     MTest_Init( &argc, &argv );
26
27     /* The following illustrates the use of the routines to 
28        run through a selection of communicators and datatypes.
29        Use subsets of these for tests that do not involve combinations 
30        of communicators, datatypes, and counts of datatypes */
31     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
32         if (comm == MPI_COMM_NULL) continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank( comm, &rank );
35         MPI_Comm_size( comm, &size );
36         source = 0;
37         dest   = size - 1;
38         
39         for (count = 1; count < 65000; count = count * 2) {
40             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
41
42                 MTestPrintfMsg( 1, 
43                        "Putting count = %d of sendtype %s receive type %s\n", 
44                                 count, MTestGetDatatypeName( &sendtype ),
45                                 MTestGetDatatypeName( &recvtype ) );
46
47                 /* Make sure that everyone has a recv buffer */
48                 recvtype.InitBuf( &recvtype );
49
50                 MPI_Type_extent( recvtype.datatype, &extent );
51                 MPI_Win_create( recvtype.buf, recvtype.count * extent, 
52                                 extent, MPI_INFO_NULL, comm, &win );
53                 MPI_Win_fence( 0, win );
54                 if (rank == source) {
55                     /* To improve reporting of problems about operations, we
56                        change the error handler to errors return */
57                     MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
58
59                     sendtype.InitBuf( &sendtype );
60                     
61                     err = MPI_Put( sendtype.buf, sendtype.count, 
62                                    sendtype.datatype, dest, 0, 
63                                    recvtype.count, recvtype.datatype, win );
64                     if (err) {
65                         errs++;
66                         if (errs < 10) {
67                             MTestPrintError( err );
68                         }
69                     }
70                     err = MPI_Win_fence( 0, win );
71                     if (err) {
72                         errs++;
73                         if (errs < 10) {
74                             MTestPrintError( err );
75                         }
76                     }
77                 }
78                 else if (rank == dest) {
79                     MPI_Win_fence( 0, win );
80                     /* This should have the same effect, in terms of
81                        transfering data, as a send/recv pair */
82                     err = MTestCheckRecv( 0, &recvtype );
83                     if (err) {
84                         if (errs < 10) {
85                             printf( "Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", 
86                                     MTestGetDatatypeName( &recvtype ),
87                                     MTestGetDatatypeName( &sendtype ) );
88                             /* Redo the test, with the errors printed */
89                             recvtype.printErrors = 1;
90                             (void)MTestCheckRecv( 0, &recvtype );
91                         }
92                         errs += err;
93                     }
94                 }
95                 else {
96                     MPI_Win_fence( 0, win );
97                 }
98                 MPI_Win_free( &win );
99                 MTestFreeDatatype( &sendtype );
100                 MTestFreeDatatype( &recvtype );
101             }
102         }
103         MTestFreeComm(&comm);
104     }
105
106     MTest_Finalize( errs );
107     MPI_Finalize();
108     return 0;
109 }