Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MPICH3 rma tests (15 out of 88 should be passing now)
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / epochtest.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2009 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 /*
9  * This test looks at the behavior of MPI_Win_fence and epochs.  Each 
10  * MPI_Win_fence may both begin and end both the exposure and access epochs.
11  * Thus, it is not necessary to use MPI_Win_fence in pairs.
12  *
13  * The tests have this form:
14  *    Process A             Process B
15  *     fence                 fence
16  *      put,put
17  *     fence                 fence
18  *                            put,put
19  *     fence                 fence
20  *      put,put               put,put
21  *     fence                 fence
22  */
23
24 #include "mpi.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "mpitest.h"
28
29 /*
30 static char MTEST_Descrip[] = "Put with Fences used to separate epochs";
31 */
32
33 #define MAX_PERR 10
34
35 int PrintRecvedError( const char *, MTestDatatype *, MTestDatatype * );
36
37 int main( int argc, char **argv )
38 {
39     int errs = 0, err;
40     int rank, size, source, dest;
41     int minsize = 2, count; 
42     MPI_Comm      comm;
43     MPI_Win       win;
44     MPI_Aint      extent;
45     MTestDatatype sendtype, recvtype;
46     int           onlyInt = 0;
47
48     MTest_Init( &argc, &argv );
49     /* Check for a simple choice of communicator and datatypes */
50     if (getenv( "MTEST_SIMPLE" )) onlyInt = 1;
51
52     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
53         if (comm == MPI_COMM_NULL) continue;
54         /* Determine the sender and receiver */
55         MPI_Comm_rank( comm, &rank );
56         MPI_Comm_size( comm, &size );
57         source = 0;
58         dest   = size - 1;
59         
60         for (count = 1; count < 65000; count = count * 2) {
61             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
62
63                 MTestPrintfMsg( 1, 
64                        "Putting count = %d of sendtype %s receive type %s\n", 
65                                 count, MTestGetDatatypeName( &sendtype ),
66                                 MTestGetDatatypeName( &recvtype ) );
67
68                 /* Make sure that everyone has a recv buffer */
69                 recvtype.InitBuf( &recvtype );
70
71                 MPI_Type_extent( recvtype.datatype, &extent );
72                 MPI_Win_create( recvtype.buf, recvtype.count * extent, 
73                                 extent, MPI_INFO_NULL, comm, &win );
74                 /* To improve reporting of problems about operations, we
75                    change the error handler to errors return */
76                 MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
77
78                 /* At this point, we have all of the elements that we 
79                    need to begin the multiple fence and put tests */
80                 /* Fence 1 */
81                 err = MPI_Win_fence( MPI_MODE_NOPRECEDE, win ); 
82                 if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
83                 /* Source puts */
84                 if (rank == source) {
85                     sendtype.InitBuf( &sendtype );
86                     
87                     err = MPI_Put( sendtype.buf, sendtype.count, 
88                                    sendtype.datatype, dest, 0, 
89                                    recvtype.count, recvtype.datatype, win );
90                     if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
91                 }
92
93                 /* Fence 2 */
94                 err = MPI_Win_fence( 0, win );
95                 if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
96                 /* dest checks data, then Dest puts */
97                 if (rank == dest) {
98                     err = MTestCheckRecv( 0, &recvtype );
99                     if (err) { if (errs++ < MAX_PERR) { 
100                             PrintRecvedError( "fence 2", &sendtype, &recvtype );
101                         }
102                     }
103                     sendtype.InitBuf( &sendtype );
104                     
105                     err = MPI_Put( sendtype.buf, sendtype.count, 
106                                    sendtype.datatype, source, 0, 
107                                    recvtype.count, recvtype.datatype, win );
108                     if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
109                 }
110
111                 /* Fence 3 */
112                 err = MPI_Win_fence( 0, win );
113                 if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
114                 /* src checks data, then Src and dest puts*/
115                 if (rank == source) {
116                     err = MTestCheckRecv( 0, &recvtype );
117                     if (err) { if (errs++ < MAX_PERR) { 
118                             PrintRecvedError( "fence 3", &sendtype, &recvtype );
119                         }
120                     }
121                     sendtype.InitBuf( &sendtype );
122                     
123                     err = MPI_Put( sendtype.buf, sendtype.count, 
124                                    sendtype.datatype, dest, 0, 
125                                    recvtype.count, recvtype.datatype, win );
126                     if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
127                 }
128                 if (rank == dest) {
129                     sendtype.InitBuf( &sendtype );
130                     
131                     err = MPI_Put( sendtype.buf, sendtype.count, 
132                                    sendtype.datatype, source, 0, 
133                                    recvtype.count, recvtype.datatype, win );
134                     if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
135                 }
136
137                 /* Fence 4 */
138                 err = MPI_Win_fence( MPI_MODE_NOSUCCEED, win );
139                 if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
140                 /* src and dest checks data */
141                 if (rank == source) {
142                     err = MTestCheckRecv( 0, &recvtype );
143                     if (err) { if (errs++ < MAX_PERR) { 
144                             PrintRecvedError( "src fence4", &sendtype, &recvtype );
145                         }
146                     }
147                 }
148                 if (rank == dest) {
149                     err = MTestCheckRecv( 0, &recvtype );
150                     if (err) { if (errs++ < MAX_PERR) { 
151                             PrintRecvedError( "dest fence4", &sendtype, &recvtype );
152                         }
153                     }
154                 }
155
156                 MPI_Win_free( &win );
157                 MTestFreeDatatype( &sendtype );
158                 MTestFreeDatatype( &recvtype );
159
160                 /* Only do one datatype in the simple case */
161                 if (onlyInt) break;
162             }
163             /* Only do one count in the simple case */
164             if (onlyInt) break;
165         }
166         MTestFreeComm(&comm);
167         /* Only do one communicator in the simple case */
168         if (onlyInt) break;
169     }
170
171     MTest_Finalize( errs );
172
173     
174     
175     MPI_Finalize();
176     return 0;
177 }
178
179
180 int PrintRecvedError( const char *msg, 
181                       MTestDatatype *sendtypePtr, MTestDatatype *recvtypePtr )
182 {
183     printf( "At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", 
184             msg, 
185             MTestGetDatatypeName( recvtypePtr ),
186             MTestGetDatatypeName( sendtypePtr ) );
187     /* Redo the test, with the errors printed */
188     recvtypePtr->printErrors = 1;
189     (void)MTestCheckRecv( 0, recvtypePtr );
190     return 0;
191 }