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.
13 #define LARGE_CNT_CONTIG 5500000
14 #define LARGE_CNT_NONCONTIG 1500000
17 static char MTEST_Descrip[] = "Get with Fence";
20 static inline int test(MPI_Comm comm, int rank, int source, int dest,
21 MTestDatatype * sendtype, MTestDatatype * recvtype)
29 "Getting count = %ld of sendtype %s - count = %ld receive type %s\n",
30 sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count,
31 MTestGetDatatypeName(recvtype));
32 /* Make sure that everyone has a recv buffer */
33 recvtype->InitBuf(recvtype);
34 sendtype->InitBuf(sendtype);
35 /* By default, print information about errors */
36 recvtype->printErrors = 1;
37 sendtype->printErrors = 1;
39 MPI_Type_extent(sendtype->datatype, &extent);
40 MPI_Type_lb(sendtype->datatype, &lb);
41 disp_unit = extent < INT_MAX ? extent : 1;
42 MPI_Win_create(sendtype->buf, sendtype->count * extent + lb, disp_unit, MPI_INFO_NULL, comm, &win);
43 MPI_Win_fence(0, win);
45 /* The source does not need to do anything besides the
47 MPI_Win_fence(0, win);
49 else if (rank == dest) {
50 /* To improve reporting of problems about operations, we
51 * change the error handler to errors return */
52 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
54 /* This should have the same effect, in terms of
55 * transfering data, as a send/recv pair */
56 err = MPI_Get(recvtype->buf, recvtype->count,
57 recvtype->datatype, source, 0, sendtype->count, sendtype->datatype, win);
64 err = MPI_Win_fence(0, win);
71 err = MTestCheckRecv(0, recvtype);
77 MPI_Win_fence(0, win);
85 int main(int argc, char *argv[])
88 int rank, size, source, dest;
89 int minsize = 2, count;
91 MTestDatatype sendtype, recvtype;
93 MTest_Init(&argc, &argv);
95 /* The following illustrates the use of the routines to
96 * run through a selection of communicators and datatypes.
97 * Use subsets of these for tests that do not involve combinations
98 * of communicators, datatypes, and counts of datatypes */
99 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
100 if (comm == MPI_COMM_NULL)
102 /* Determine the sender and receiver */
103 MPI_Comm_rank(comm, &rank);
104 MPI_Comm_size(comm, &size);
108 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
109 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
110 errs += test(comm, rank, source, dest, &sendtype, &recvtype);
111 MTestFreeDatatype(&sendtype);
112 MTestFreeDatatype(&recvtype);
115 MTestFreeComm(&comm);
118 /* Part #2: simple large size test - contiguous and noncontiguous */
119 if (sizeof(void *) > 4) { /* Only if > 32-bit architecture */
120 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
121 MPI_Comm_size(MPI_COMM_WORLD, &size);
125 MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
126 errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
129 MTestFreeDatatype(&sendtype);
130 MTestFreeDatatype(&recvtype);
131 MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG);
132 } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL);
133 errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
134 MTestFreeDatatype(&sendtype);
135 MTestFreeDatatype(&recvtype);
138 MTest_Finalize(errs);