1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2009 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
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.
13 * The tests have this form:
30 static char MTEST_Descrip[] = "Put with Fences used to separate epochs";
35 int PrintRecvedError(const char *, MTestDatatype *, MTestDatatype *);
37 int main(int argc, char **argv)
40 int rank, size, source, dest;
41 int minsize = 2, count;
45 MTestDatatype sendtype, recvtype;
48 MTest_Init(&argc, &argv);
49 /* Check for a simple choice of communicator and datatypes */
50 if (getenv("MTEST_SIMPLE"))
53 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
54 if (comm == MPI_COMM_NULL)
56 /* Determine the sender and receiver */
57 MPI_Comm_rank(comm, &rank);
58 MPI_Comm_size(comm, &size);
62 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
63 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
66 "Putting count = %d of sendtype %s receive type %s\n",
67 count, MTestGetDatatypeName(&sendtype),
68 MTestGetDatatypeName(&recvtype));
70 /* Make sure that everyone has a recv buffer */
71 recvtype.InitBuf(&recvtype);
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);
81 /* At this point, we have all of the elements that we
82 * need to begin the multiple fence and put tests */
84 err = MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
86 if (errs++ < MAX_PERR)
91 sendtype.InitBuf(&sendtype);
93 err = MPI_Put(sendtype.buf, sendtype.count,
94 sendtype.datatype, dest, 0,
95 recvtype.count, recvtype.datatype, win);
97 if (errs++ < MAX_PERR)
103 err = MPI_Win_fence(0, win);
105 if (errs++ < MAX_PERR)
106 MTestPrintError(err);
108 /* dest checks data, then Dest puts */
110 err = MTestCheckRecv(0, &recvtype);
112 if (errs++ < MAX_PERR) {
113 PrintRecvedError("fence 2", &sendtype, &recvtype);
116 sendtype.InitBuf(&sendtype);
118 err = MPI_Put(sendtype.buf, sendtype.count,
119 sendtype.datatype, source, 0,
120 recvtype.count, recvtype.datatype, win);
122 if (errs++ < MAX_PERR)
123 MTestPrintError(err);
128 err = MPI_Win_fence(0, win);
130 if (errs++ < MAX_PERR)
131 MTestPrintError(err);
133 /* src checks data, then Src and dest puts */
134 if (rank == source) {
135 err = MTestCheckRecv(0, &recvtype);
137 if (errs++ < MAX_PERR) {
138 PrintRecvedError("fence 3", &sendtype, &recvtype);
141 sendtype.InitBuf(&sendtype);
143 err = MPI_Put(sendtype.buf, sendtype.count,
144 sendtype.datatype, dest, 0,
145 recvtype.count, recvtype.datatype, win);
147 if (errs++ < MAX_PERR)
148 MTestPrintError(err);
152 sendtype.InitBuf(&sendtype);
154 err = MPI_Put(sendtype.buf, sendtype.count,
155 sendtype.datatype, source, 0,
156 recvtype.count, recvtype.datatype, win);
158 if (errs++ < MAX_PERR)
159 MTestPrintError(err);
164 err = MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
166 if (errs++ < MAX_PERR)
167 MTestPrintError(err);
169 /* src and dest checks data */
170 if (rank == source) {
171 err = MTestCheckRecv(0, &recvtype);
173 if (errs++ < MAX_PERR) {
174 PrintRecvedError("src fence4", &sendtype, &recvtype);
179 err = MTestCheckRecv(0, &recvtype);
181 if (errs++ < MAX_PERR) {
182 PrintRecvedError("dest fence4", &sendtype, &recvtype);
188 MTestFreeDatatype(&sendtype);
189 MTestFreeDatatype(&recvtype);
191 /* Only do one datatype in the simple case */
195 /* Only do one count in the simple case */
199 MTestFreeComm(&comm);
200 /* Only do one communicator in the simple case */
205 MTest_Finalize(errs);
214 int PrintRecvedError(const char *msg, MTestDatatype * sendtypePtr, MTestDatatype * recvtypePtr)
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);