Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / accfence1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Accumulate/Replace with Fence";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count;
20     MPI_Comm comm;
21     MPI_Win win;
22     MPI_Aint extent, lb;
23     MTestDatatype sendtype, recvtype;
24
25     MTest_Init(&argc, &argv);
26
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)
33             continue;
34         /* Determine the sender and receiver */
35         MPI_Comm_rank(comm, &rank);
36         MPI_Comm_size(comm, &size);
37         source = 0;
38         dest = size - 1;
39
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);
44
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);
50                 if (rank == source) {
51                     sendtype.InitBuf(&sendtype);
52
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);
56
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);
64                     if (err) {
65                         errs++;
66                         if (errs < 10) {
67                             printf("Accumulate types: send %s, recv %s\n",
68                                    MTestGetDatatypeName(&sendtype),
69                                    MTestGetDatatypeName(&recvtype));
70                             MTestPrintError(err);
71                         }
72                     }
73                     err = MPI_Win_fence(0, win);
74                     if (err) {
75                         errs++;
76                         if (errs < 10) {
77                             MTestPrintError(err);
78                         }
79                     }
80                 }
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);
86                     if (err) {
87                         errs += err;
88                     }
89                 }
90                 else {
91                     MPI_Win_fence(0, win);
92                 }
93                 MPI_Win_free(&win);
94                 MTestFreeDatatype(&sendtype);
95                 MTestFreeDatatype(&recvtype);
96             }
97         }
98         MTestFreeComm(&comm);
99     }
100
101     MTest_Finalize(errs);
102     MPI_Finalize();
103     return 0;
104 }