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 Post/Start/Complete/Wait";
15 int main(int argc, char *argv[])
18 int rank, size, source, dest;
19 int minsize = 2, count;
23 MPI_Group wingroup, neighbors;
24 MTestDatatype sendtype, recvtype;
26 MTest_Init(&argc, &argv);
28 /* The following illustrates the use of the routines to
29 * run through a selection of communicators and datatypes.
30 * Use subsets of these for tests that do not involve combinations
31 * of communicators, datatypes, and counts of datatypes */
32 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
33 if (comm == MPI_COMM_NULL)
35 /* Determine the sender and receiver */
36 MPI_Comm_rank(comm, &rank);
37 MPI_Comm_size(comm, &size);
41 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
42 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
43 /* Make sure that everyone has a recv buffer */
44 recvtype.InitBuf(&recvtype);
46 MPI_Type_extent(recvtype.datatype, &extent);
47 MPI_Type_lb(recvtype.datatype, &lb);
48 MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
49 (int) extent, MPI_INFO_NULL, comm, &win);
50 MPI_Win_get_group(win, &wingroup);
52 /* To improve reporting of problems about operations, we
53 * change the error handler to errors return */
54 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
55 sendtype.InitBuf(&sendtype);
57 /* Neighbor is dest only */
58 MPI_Group_incl(wingroup, 1, &dest, &neighbors);
59 err = MPI_Win_start(neighbors, 0, win);
66 MPI_Group_free(&neighbors);
67 err = MPI_Accumulate(sendtype.buf, sendtype.count,
68 sendtype.datatype, dest, 0,
69 recvtype.count, recvtype.datatype, MPI_REPLACE, win);
74 err = MPI_Win_complete(win);
82 else if (rank == dest) {
83 MPI_Group_incl(wingroup, 1, &source, &neighbors);
84 MPI_Win_post(neighbors, 0, win);
85 MPI_Group_free(&neighbors);
87 /* This should have the same effect, in terms of
88 * transferring data, as a send/recv pair */
89 err = MTestCheckRecv(0, &recvtype);
95 /* Nothing; the other processes need not call any
100 MTestFreeDatatype(&sendtype);
101 MTestFreeDatatype(&recvtype);
102 MPI_Group_free(&wingroup);
105 MTestFreeComm(&comm);
108 MTest_Finalize(errs);