1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 /* These counts allow reasonable sizes for the large tests */
13 #define LARGE_CNT_CONTIG 5500000
14 #define LARGE_CNT_NONCONTIG 1500000
17 static char MTEST_Descrip[] = "Put with Fence";
20 static inline int test(MPI_Comm comm, int rank, int source, int dest,
21 MTestDatatype * sendtype, MTestDatatype * recvtype)
28 "Putting count = %ld of sendtype %s - count = %ld receive type %s\n",
29 sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count,
30 MTestGetDatatypeName(recvtype));
32 /* Make sure that everyone has a recv buffer */
33 recvtype->InitBuf(recvtype);
34 MPI_Type_extent(recvtype->datatype, &extent);
35 MPI_Type_lb(recvtype->datatype, &lb);
36 MPI_Win_create(recvtype->buf, recvtype->count * extent + lb, extent, MPI_INFO_NULL, comm, &win);
37 MPI_Win_fence(0, win);
39 /* To improve reporting of problems about operations, we
40 * change the error handler to errors return */
41 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
43 sendtype->InitBuf(sendtype);
45 err = MPI_Put(sendtype->buf, sendtype->count,
46 sendtype->datatype, dest, 0, recvtype->count, recvtype->datatype, win);
53 err = MPI_Win_fence(0, win);
61 else if (rank == dest) {
62 MPI_Win_fence(0, win);
63 /* This should have the same effect, in terms of
64 * transfering data, as a send/recv pair */
65 err = MTestCheckRecv(0, recvtype);
69 ("Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n",
70 MTestGetDatatypeName(recvtype), MTestGetDatatypeName(sendtype));
71 /* Redo the test, with the errors printed */
72 recvtype->printErrors = 1;
73 (void) MTestCheckRecv(0, recvtype);
79 MPI_Win_fence(0, win);
87 int main(int argc, char *argv[])
90 int rank, size, source, dest;
91 int minsize = 2, count;
93 MTestDatatype sendtype, recvtype;
95 MTest_Init(&argc, &argv);
96 /* The following illustrates the use of the routines to
97 * run through a selection of communicators and datatypes.
98 * Use subsets of these for tests that do not involve combinations
99 * of communicators, datatypes, and counts of datatypes */
100 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
101 if (comm == MPI_COMM_NULL)
103 /* Determine the sender and receiver */
104 MPI_Comm_rank(comm, &rank);
105 MPI_Comm_size(comm, &size);
109 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
110 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
111 errs += test(comm, rank, source, dest, &sendtype, &recvtype);
112 MTestFreeDatatype(&sendtype);
113 MTestFreeDatatype(&recvtype);
116 MTestFreeComm(&comm);
119 /* Part #2: simple large size test - contiguous and noncontiguous */
120 if (sizeof(void *) > 4) { /* Only if > 32-bit architecture */
121 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
122 MPI_Comm_size(MPI_COMM_WORLD, &size);
126 MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
127 errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
130 MTestFreeDatatype(&sendtype);
131 MTestFreeDatatype(&recvtype);
132 MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG);
133 } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL);
134 errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
135 MTestFreeDatatype(&sendtype);
136 MTestFreeDatatype(&recvtype);
139 MTest_Finalize(errs);