Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[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,lb;
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"))
51         onlyInt = 1;
52
53     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
54         if (comm == MPI_COMM_NULL)
55             continue;
56         /* Determine the sender and receiver */
57         MPI_Comm_rank(comm, &rank);
58         MPI_Comm_size(comm, &size);
59         source = 0;
60         dest = size - 1;
61
62         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
63             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
64
65                 MTestPrintfMsg(1,
66                                "Putting count = %d of sendtype %s receive type %s\n",
67                                count, MTestGetDatatypeName(&sendtype),
68                                MTestGetDatatypeName(&recvtype));
69
70                 /* Make sure that everyone has a recv buffer */
71                 recvtype.InitBuf(&recvtype);
72
73                 MPI_Type_extent(recvtype.datatype, &extent);
74                 MPI_Type_lb(recvtype.datatype, &lb);
75                 MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
76                                extent, MPI_INFO_NULL, comm, &win);
77                 /* To improve reporting of problems about operations, we
78                  * change the error handler to errors return */
79                 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
80
81                 /* At this point, we have all of the elements that we
82                  * need to begin the multiple fence and put tests */
83                 /* Fence 1 */
84                 err = MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
85                 if (err) {
86                     if (errs++ < MAX_PERR)
87                         MTestPrintError(err);
88                 }
89                 /* Source puts */
90                 if (rank == source) {
91                     sendtype.InitBuf(&sendtype);
92
93                     err = MPI_Put(sendtype.buf, sendtype.count,
94                                   sendtype.datatype, dest, 0,
95                                   recvtype.count, recvtype.datatype, win);
96                     if (err) {
97                         if (errs++ < MAX_PERR)
98                             MTestPrintError(err);
99                     }
100                 }
101
102                 /* Fence 2 */
103                 err = MPI_Win_fence(0, win);
104                 if (err) {
105                     if (errs++ < MAX_PERR)
106                         MTestPrintError(err);
107                 }
108                 /* dest checks data, then Dest puts */
109                 if (rank == dest) {
110                     err = MTestCheckRecv(0, &recvtype);
111                     if (err) {
112                         if (errs++ < MAX_PERR) {
113                             PrintRecvedError("fence 2", &sendtype, &recvtype);
114                         }
115                     }
116                     sendtype.InitBuf(&sendtype);
117
118                     err = MPI_Put(sendtype.buf, sendtype.count,
119                                   sendtype.datatype, source, 0,
120                                   recvtype.count, recvtype.datatype, win);
121                     if (err) {
122                         if (errs++ < MAX_PERR)
123                             MTestPrintError(err);
124                     }
125                 }
126
127                 /* Fence 3 */
128                 err = MPI_Win_fence(0, win);
129                 if (err) {
130                     if (errs++ < MAX_PERR)
131                         MTestPrintError(err);
132                 }
133                 /* src checks data, then Src and dest puts */
134                 if (rank == source) {
135                     err = MTestCheckRecv(0, &recvtype);
136                     if (err) {
137                         if (errs++ < MAX_PERR) {
138                             PrintRecvedError("fence 3", &sendtype, &recvtype);
139                         }
140                     }
141                     sendtype.InitBuf(&sendtype);
142
143                     err = MPI_Put(sendtype.buf, sendtype.count,
144                                   sendtype.datatype, dest, 0,
145                                   recvtype.count, recvtype.datatype, win);
146                     if (err) {
147                         if (errs++ < MAX_PERR)
148                             MTestPrintError(err);
149                     }
150                 }
151                 if (rank == dest) {
152                     sendtype.InitBuf(&sendtype);
153
154                     err = MPI_Put(sendtype.buf, sendtype.count,
155                                   sendtype.datatype, source, 0,
156                                   recvtype.count, recvtype.datatype, win);
157                     if (err) {
158                         if (errs++ < MAX_PERR)
159                             MTestPrintError(err);
160                     }
161                 }
162
163                 /* Fence 4 */
164                 err = MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
165                 if (err) {
166                     if (errs++ < MAX_PERR)
167                         MTestPrintError(err);
168                 }
169                 /* src and dest checks data */
170                 if (rank == source) {
171                     err = MTestCheckRecv(0, &recvtype);
172                     if (err) {
173                         if (errs++ < MAX_PERR) {
174                             PrintRecvedError("src fence4", &sendtype, &recvtype);
175                         }
176                     }
177                 }
178                 if (rank == dest) {
179                     err = MTestCheckRecv(0, &recvtype);
180                     if (err) {
181                         if (errs++ < MAX_PERR) {
182                             PrintRecvedError("dest fence4", &sendtype, &recvtype);
183                         }
184                     }
185                 }
186
187                 MPI_Win_free(&win);
188                 MTestFreeDatatype(&sendtype);
189                 MTestFreeDatatype(&recvtype);
190
191                 /* Only do one datatype in the simple case */
192                 if (onlyInt)
193                     break;
194             }
195             /* Only do one count in the simple case */
196             if (onlyInt)
197                 break;
198         }
199         MTestFreeComm(&comm);
200         /* Only do one communicator in the simple case */
201         if (onlyInt)
202             break;
203     }
204
205     MTest_Finalize(errs);
206
207
208
209     MPI_Finalize();
210     return 0;
211 }
212
213
214 int PrintRecvedError(const char *msg, MTestDatatype * sendtypePtr, MTestDatatype * recvtypePtr)
215 {
216     printf
217         ("At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n",
218          msg, MTestGetDatatypeName(recvtypePtr), MTestGetDatatypeName(sendtypePtr));
219     /* Redo the test, with the errors printed */
220     recvtypePtr->printErrors = 1;
221     (void) MTestCheckRecv(0, recvtypePtr);
222     return 0;
223 }