Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / putfence1.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 <string.h>
10 #include "mpitest.h"
11
12 /* These counts allow reasonable sizes for the large tests */
13 #define LARGE_CNT_CONTIG    5500000
14 #define LARGE_CNT_NONCONTIG 1500000
15
16 /*
17 static char MTEST_Descrip[] = "Put with Fence";
18 */
19
20 static inline int test(MPI_Comm comm, int rank, int source, int dest,
21                        MTestDatatype * sendtype, MTestDatatype * recvtype)
22 {
23     int errs = 0, err;
24     MPI_Aint extent, lb;
25     MPI_Win win;
26
27     MTestPrintfMsg(1,
28                    "Putting count = %ld of sendtype %s - count = %ld receive type %s\n",
29                    sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count,
30                    MTestGetDatatypeName(recvtype));
31
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);
38     if (rank == source) {
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);
42
43         sendtype->InitBuf(sendtype);
44
45         err = MPI_Put(sendtype->buf, sendtype->count,
46                       sendtype->datatype, dest, 0, recvtype->count, recvtype->datatype, win);
47         if (err) {
48             errs++;
49             if (errs < 10) {
50                 MTestPrintError(err);
51             }
52         }
53         err = MPI_Win_fence(0, win);
54         if (err) {
55             errs++;
56             if (errs < 10) {
57                 MTestPrintError(err);
58             }
59         }
60     }
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);
66         if (err) {
67             if (errs < 10) {
68                 printf
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);
74             }
75             errs += err;
76         }
77     }
78     else {
79         MPI_Win_fence(0, win);
80     }
81     MPI_Win_free(&win);
82
83     return errs;
84 }
85
86
87 int main(int argc, char *argv[])
88 {
89     int errs = 0;
90     int rank, size, source, dest;
91     int minsize = 2, count;
92     MPI_Comm comm;
93     MTestDatatype sendtype, recvtype;
94
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)
102             continue;
103         /* Determine the sender and receiver */
104         MPI_Comm_rank(comm, &rank);
105         MPI_Comm_size(comm, &size);
106         source = 0;
107         dest = size - 1;
108
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);
114             }
115         }
116         MTestFreeComm(&comm);
117     }
118
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);
123         source = 0;
124         dest = size - 1;
125
126         MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
127         errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
128
129         do {
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);
137     }
138
139     MTest_Finalize(errs);
140     MPI_Finalize();
141     return 0;
142 }