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 / rmanull.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2010 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /* Test the given operation within a Fence epoch */
13 #define TEST_FENCE_OP(op_name_, fcn_call_)                              \
14     do {                                                                \
15         err = fcn_call_                                                 \
16         if (err) {                                                      \
17             errs++;                                                     \
18             if (errs < 10) {                                            \
19                 MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
20             }                                                           \
21         }                                                               \
22         err = MPI_Win_fence(0, win);                                  \
23         if (err) {                                                      \
24             errs++;                                                     \
25             if (errs < 10) {                                            \
26                 MTestPrintErrorMsg("Fence after " op_name_, err);     \
27             }                                                           \
28         }                                                               \
29     } while (0)
30
31
32 /* Test the given operation within a passive target epoch */
33 #define TEST_PT_OP(op_name_, fcn_call_)                                 \
34     do {                                                                \
35         err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, MPI_PROC_NULL, 0, win);  \
36         if (err) {                                                      \
37             errs++;                                                     \
38             if (errs < 10) {                                            \
39                 MTestPrintErrorMsg("Lock before" op_name_, err);      \
40             }                                                           \
41         }                                                               \
42         err = fcn_call_                                                 \
43         if (err) {                                                      \
44             errs++;                                                     \
45             if (errs < 10) {                                            \
46                 MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
47             }                                                           \
48         }                                                               \
49         err = MPI_Win_unlock(MPI_PROC_NULL, win);                     \
50         if (err) {                                                      \
51             errs++;                                                     \
52             if (errs < 10) {                                            \
53                 MTestPrintErrorMsg("Unlock after " op_name_, err);    \
54             }                                                           \
55         }                                                               \
56     } while (0)
57
58
59 /* Test the given request-based operation within a passive target epoch */
60 #define TEST_REQ_OP(op_name_, req_, fcn_call_)                          \
61     do {                                                                \
62         err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, MPI_PROC_NULL, 0, win);  \
63         if (err) {                                                      \
64             errs++;                                                     \
65             if (errs < 10) {                                            \
66                 MTestPrintErrorMsg("Lock before" op_name_, err);      \
67             }                                                           \
68         }                                                               \
69         err = fcn_call_                                                 \
70         if (err) {                                                      \
71             errs++;                                                     \
72             if (errs < 10) {                                            \
73                 MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
74             }                                                           \
75         }                                                               \
76         err = MPI_Win_unlock(MPI_PROC_NULL, win);                     \
77         if (err) {                                                      \
78             errs++;                                                     \
79             if (errs < 10) {                                            \
80                 MTestPrintErrorMsg("Unlock after " op_name_, err);    \
81             }                                                           \
82         }                                                               \
83         err = MPI_Wait(&req_, MPI_STATUS_IGNORE);                     \
84         if (err) {                                                      \
85             errs++;                                                     \
86             if (errs < 10) {                                            \
87                 MTestPrintErrorMsg("Wait after " op_name_, err);      \
88             }                                                           \
89         }                                                               \
90     } while (0)
91
92 /*
93 static char MTEST_Descrip[] = "Test the MPI_PROC_NULL is a valid target";
94 */
95
96 int main(int argc, char *argv[])
97 {
98     int errs = 0, err;
99     int rank, size;
100     int *buf, bufsize;
101     int *result;
102     int *rmabuf, rsize, rcount;
103     MPI_Comm comm;
104     MPI_Win win;
105     MPI_Request req;
106
107     MTest_Init(&argc, &argv);
108
109     bufsize = 256 * sizeof(int);
110     buf = (int *) malloc(bufsize);
111     if (!buf) {
112         fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
113         MPI_Abort(MPI_COMM_WORLD, 1);
114     }
115     result = (int *) malloc(bufsize);
116     if (!result) {
117         fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
118         MPI_Abort(MPI_COMM_WORLD, 1);
119     }
120     rcount = 16;
121     rsize = rcount * sizeof(int);
122     rmabuf = (int *) malloc(rsize);
123     if (!rmabuf) {
124         fprintf(stderr, "Unable to allocated %d bytes\n", rsize);
125         MPI_Abort(MPI_COMM_WORLD, 1);
126     }
127
128     /* The following illustrates the use of the routines to
129      * run through a selection of communicators and datatypes.
130      * Use subsets of these for tests that do not involve combinations
131      * of communicators, datatypes, and counts of datatypes */
132     while (MTestGetIntracommGeneral(&comm, 1, 1)) {
133         if (comm == MPI_COMM_NULL)
134             continue;
135         /* Determine the sender and receiver */
136         MPI_Comm_rank(comm, &rank);
137         MPI_Comm_size(comm, &size);
138
139         MPI_Win_create(buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win);
140         /* To improve reporting of problems about operations, we
141          * change the error handler to errors return */
142         MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
143
144         /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
145         MPI_Win_fence(0, win);
146
147         TEST_FENCE_OP("Put",
148                       MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
149 );
150
151         TEST_FENCE_OP("Get",
152                       MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
153 );
154         TEST_FENCE_OP("Accumulate",
155                       MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL,
156                                      0, rcount, MPI_INT, MPI_SUM, win);
157 );
158         TEST_FENCE_OP("Get accumulate",
159                       MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result,
160                                          rcount, MPI_INT, MPI_PROC_NULL, 0,
161                                          rcount, MPI_INT, MPI_SUM, win);
162 );
163         TEST_FENCE_OP("Fetch and op",
164                       MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win);
165 );
166         TEST_FENCE_OP("Compare and swap",
167                       MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win);
168 );
169
170         /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
171
172         TEST_PT_OP("Put", MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
173 );
174         TEST_PT_OP("Get", MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
175 );
176         TEST_PT_OP("Accumulate",
177                    MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
178                                   rcount, MPI_INT, MPI_SUM, win);
179 );
180         TEST_PT_OP("Get accumulate",
181                    MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result, rcount,
182                                       MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, MPI_SUM, win);
183 );
184         TEST_PT_OP("Fetch and op",
185                    MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win);
186 );
187         TEST_PT_OP("Compare and swap",
188                    MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win);
189 );
190
191         /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
192
193         TEST_REQ_OP("Rput", req,
194                     MPI_Rput(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req);
195 );
196         TEST_REQ_OP("Rget", req,
197                     MPI_Rget(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req);
198 );
199         TEST_REQ_OP("Raccumulate", req,
200                     MPI_Raccumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
201                                     rcount, MPI_INT, MPI_SUM, win, &req);
202 );
203         TEST_REQ_OP("Rget_accumulate", req,
204                     MPI_Rget_accumulate(rmabuf, rcount, MPI_INT, result,
205                                         rcount, MPI_INT, MPI_PROC_NULL, 0,
206                                         rcount, MPI_INT, MPI_SUM, win, &req);
207 );
208
209         MPI_Win_free(&win);
210         MTestFreeComm(&comm);
211     }
212
213     free(result);
214     free(buf);
215     free(rmabuf);
216     MTest_Finalize(errs);
217     MPI_Finalize();
218     return 0;
219 }