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 / getfence1.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 <limits.h>
11 #include "mpitest.h"
12
13 #define LARGE_CNT_CONTIG    5500000
14 #define LARGE_CNT_NONCONTIG 1500000
15
16 /*
17 static char MTEST_Descrip[] = "Get 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     int disp_unit;
25     MPI_Aint extent, lb;
26     MPI_Win win;
27
28     MTestPrintfMsg(1,
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;
38
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);
44     if (rank == source) {
45         /* The source does not need to do anything besides the
46          * fence */
47         MPI_Win_fence(0, win);
48     }
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);
53
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);
58         if (err) {
59             errs++;
60             if (errs < 10) {
61                 MTestPrintError(err);
62             }
63         }
64         err = MPI_Win_fence(0, win);
65         if (err) {
66             errs++;
67             if (errs < 10) {
68                 MTestPrintError(err);
69             }
70         }
71         err = MTestCheckRecv(0, recvtype);
72         if (err) {
73             errs += err;
74         }
75     }
76     else {
77         MPI_Win_fence(0, win);
78     }
79     MPI_Win_free(&win);
80
81     return errs;
82 }
83
84
85 int main(int argc, char *argv[])
86 {
87     int errs = 0;
88     int rank, size, source, dest;
89     int minsize = 2, count;
90     MPI_Comm comm;
91     MTestDatatype sendtype, recvtype;
92
93     MTest_Init(&argc, &argv);
94
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)
101             continue;
102         /* Determine the sender and receiver */
103         MPI_Comm_rank(comm, &rank);
104         MPI_Comm_size(comm, &size);
105         source = 0;
106         dest = size - 1;
107
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);
113             }
114         }
115         MTestFreeComm(&comm);
116     }
117
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);
122         source = 0;
123         dest = size - 1;
124
125         MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
126         errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
127
128         do {
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);
136     }
137
138     MTest_Finalize(errs);
139     MPI_Finalize();
140     return 0;
141 }