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 static char MTEST_Descrip[] = "Accumulate/Replace with Fence";
15 int main(int argc, char *argv[])
18 int rank, size, source, dest;
19 int minsize = 2, count;
23 MTestDatatype sendtype, recvtype;
25 MTest_Init(&argc, &argv);
27 /* The following illustrates the use of the routines to
28 * run through a selection of communicators and datatypes.
29 * Use subsets of these for tests that do not involve combinations
30 * of communicators, datatypes, and counts of datatypes */
31 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
32 if (comm == MPI_COMM_NULL)
34 /* Determine the sender and receiver */
35 MPI_Comm_rank(comm, &rank);
36 MPI_Comm_size(comm, &size);
40 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
41 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
42 /* Make sure that everyone has a recv buffer */
43 recvtype.InitBuf(&recvtype);
45 MPI_Type_extent(recvtype.datatype, &extent);
46 MPI_Type_lb(recvtype.datatype, &lb);
47 MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
48 (int) extent, MPI_INFO_NULL, comm, &win);
49 MPI_Win_fence(0, win);
51 sendtype.InitBuf(&sendtype);
53 /* To improve reporting of problems about operations, we
54 * change the error handler to errors return */
55 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
57 /* MPI_REPLACE on accumulate is almost the same
58 * as MPI_Put; the only difference is in the
59 * handling of overlapping accumulate operations,
60 * which are not tested here */
61 err = MPI_Accumulate(sendtype.buf, sendtype.count,
62 sendtype.datatype, dest, 0,
63 recvtype.count, recvtype.datatype, MPI_REPLACE, win);
67 printf("Accumulate types: send %s, recv %s\n",
68 MTestGetDatatypeName(&sendtype),
69 MTestGetDatatypeName(&recvtype));
73 err = MPI_Win_fence(0, win);
81 else if (rank == dest) {
82 MPI_Win_fence(0, win);
83 /* This should have the same effect, in terms of
84 * transfering data, as a send/recv pair */
85 err = MTestCheckRecv(0, &recvtype);
91 MPI_Win_fence(0, win);
94 MTestFreeDatatype(&sendtype);
95 MTestFreeDatatype(&recvtype);
101 MTest_Finalize(errs);