Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / rmazero.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 #define TARGET 0
13
14 /* Test the given operation within a Fence epoch */
15 #define TEST_FENCE_OP(op_name_, fcn_call_)                              \
16     do {                                                                \
17         err = fcn_call_                                                 \
18         if (err) {                                                      \
19             errs++;                                                     \
20             if (errs < 10) {                                            \
21                 MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
22             }                                                           \
23         }                                                               \
24         err = MPI_Win_fence( 0, win );                                  \
25         if (err) {                                                      \
26             errs++;                                                     \
27             if (errs < 10) {                                            \
28                 MTestPrintErrorMsg( "Fence after " op_name_, err );     \
29             }                                                           \
30         }                                                               \
31     } while (0)
32
33
34 /* Test the given operation within a passive target epoch */
35 #define TEST_PT_OP(op_name_, fcn_call_)                                 \
36     do {                                                                \
37         err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, TARGET, 0, win);         \
38         if (err) {                                                      \
39             errs++;                                                     \
40             if (errs < 10) {                                            \
41                 MTestPrintErrorMsg( "Lock before" op_name_, err );      \
42             }                                                           \
43         }                                                               \
44         err = fcn_call_                                                 \
45         if (err) {                                                      \
46             errs++;                                                     \
47             if (errs < 10) {                                            \
48                 MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
49             }                                                           \
50         }                                                               \
51         err = MPI_Win_unlock( TARGET, win );                            \
52         if (err) {                                                      \
53             errs++;                                                     \
54             if (errs < 10) {                                            \
55                 MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
56             }                                                           \
57         }                                                               \
58     } while (0)
59
60
61 /* Test the given request-based operation within a passive target epoch */
62 #define TEST_REQ_OP(op_name_, req_, fcn_call_)                          \
63     do {                                                                \
64         err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, TARGET, 0, win);         \
65         if (err) {                                                      \
66             errs++;                                                     \
67             if (errs < 10) {                                            \
68                 MTestPrintErrorMsg( "Lock before" op_name_, err );      \
69             }                                                           \
70         }                                                               \
71         err = fcn_call_                                                 \
72         if (err) {                                                      \
73             errs++;                                                     \
74             if (errs < 10) {                                            \
75                 MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
76             }                                                           \
77         }                                                               \
78         err = MPI_Win_unlock( TARGET, win );                            \
79         if (err) {                                                      \
80             errs++;                                                     \
81             if (errs < 10) {                                            \
82                 MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
83             }                                                           \
84         }                                                               \
85         err = MPI_Wait( &req_, MPI_STATUS_IGNORE );                     \
86         if (err) {                                                      \
87             errs++;                                                     \
88             if (errs < 10) {                                            \
89                 MTestPrintErrorMsg( "Wait after " op_name_, err );      \
90             }                                                           \
91         }                                                               \
92     } while (0)
93
94 /*
95 static char MTEST_Descrip[] = "Test handling of zero-byte transfers";
96 */
97
98 int main( int argc, char *argv[] )
99 {
100     int           errs = 0, err;
101     int           rank, size;
102     int           *buf, bufsize;
103     int           *result;
104     int           *rmabuf, rsize, rcount;
105     MPI_Comm      comm;
106     MPI_Win       win;
107     MPI_Request   req;
108     MPI_Datatype  derived_dtp;
109
110     MTest_Init( &argc, &argv );
111
112     bufsize = 256 * sizeof(int);
113     buf     = (int *)malloc( bufsize );
114     if (!buf) {
115         fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
116         MPI_Abort( MPI_COMM_WORLD, 1 );
117     }
118     result  = (int *)malloc( bufsize );
119     if (!result) {
120         fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
121         MPI_Abort( MPI_COMM_WORLD, 1 );
122     }
123     rcount   = 16;
124     rsize    = rcount * sizeof(int);
125     rmabuf   = (int *)malloc( rsize );
126     if (!rmabuf) {
127         fprintf( stderr, "Unable to allocated %d bytes\n", rsize );
128         MPI_Abort( MPI_COMM_WORLD, 1 );
129     }
130
131     MPI_Type_contiguous(2, MPI_INT, &derived_dtp);
132     MPI_Type_commit(&derived_dtp);
133
134     /* The following loop is used to run through a series of communicators
135      * that are subsets of MPI_COMM_WORLD, of size 1 or greater. */
136     while (MTestGetIntracommGeneral( &comm, 1, 1 )) {
137         int count = 0;
138
139         if (comm == MPI_COMM_NULL) continue;
140         /* Determine the sender and receiver */
141         MPI_Comm_rank( comm, &rank );
142         MPI_Comm_size( comm, &size );
143
144         MPI_Win_create( buf, bufsize, 2*sizeof(int), MPI_INFO_NULL, comm, &win );
145         /* To improve reporting of problems about operations, we
146            change the error handler to errors return */
147         MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
148
149         /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
150         MPI_Win_fence( 0, win );
151
152         TEST_FENCE_OP("Put",
153                       MPI_Put( rmabuf, count, MPI_INT, TARGET, 0,
154                                count, MPI_INT, win );
155                      );
156
157         TEST_FENCE_OP("Get",
158                       MPI_Get( rmabuf, count, MPI_INT, TARGET, 0,
159                                count, MPI_INT, win );
160                      );
161         TEST_FENCE_OP("Accumulate",
162                       MPI_Accumulate( rmabuf, count, MPI_INT, TARGET,
163                                       0, count, MPI_INT, MPI_SUM, win );
164                      );
165         TEST_FENCE_OP("Accumulate_derived",
166                       MPI_Accumulate( rmabuf, count, derived_dtp, TARGET,
167                                       0, count, derived_dtp, MPI_SUM, win );
168                      );
169         TEST_FENCE_OP("Get accumulate",
170                       MPI_Get_accumulate( rmabuf, count, MPI_INT, result,
171                                           count, MPI_INT, TARGET, 0,
172                                           count, MPI_INT, MPI_SUM, win );
173                      );
174         /* Note: It's not possible to generate a zero-byte FOP or CAS */
175
176         /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
177
178         TEST_PT_OP("Put",
179                    MPI_Put( rmabuf, count, MPI_INT, TARGET, 0, count,
180                             MPI_INT, win );
181                    );
182         TEST_PT_OP("Get",
183                    MPI_Get( rmabuf, count, MPI_INT, TARGET, 0, count,
184                             MPI_INT, win );
185                    );
186         TEST_PT_OP("Accumulate",
187                    MPI_Accumulate( rmabuf, count, MPI_INT, TARGET, 0,
188                                    count, MPI_INT, MPI_SUM, win );
189                    );
190         TEST_PT_OP("Accumulate_derived",
191                    MPI_Accumulate( rmabuf, count, derived_dtp, TARGET, 0,
192                                    count, derived_dtp, MPI_SUM, win );
193                    );
194         TEST_PT_OP("Get accumulate",
195                    MPI_Get_accumulate( rmabuf, count, MPI_INT, result, count,
196                                        MPI_INT, TARGET, 0, count,
197                                        MPI_INT, MPI_SUM, win );
198                    );
199
200         /* Note: It's not possible to generate a zero-byte FOP or CAS */
201
202         /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
203
204         TEST_REQ_OP("Rput", req,
205                     MPI_Rput( rmabuf, count, MPI_INT, TARGET, 0, count,
206                               MPI_INT, win, &req );
207                    );
208         TEST_REQ_OP("Rget", req,
209                     MPI_Rget( rmabuf, count, MPI_INT, TARGET, 0, count,
210                               MPI_INT, win, &req );
211                    );
212         TEST_REQ_OP("Raccumulate", req,
213                     MPI_Raccumulate( rmabuf, count, MPI_INT, TARGET, 0,
214                                      count, MPI_INT, MPI_SUM, win, &req );
215                    );
216         TEST_REQ_OP("Raccumulate_derived", req,
217                     MPI_Raccumulate( rmabuf, count, derived_dtp, TARGET, 0,
218                                      count, derived_dtp, MPI_SUM, win, &req );
219                    );
220         TEST_REQ_OP("Rget_accumulate", req,
221                     MPI_Rget_accumulate( rmabuf, count, MPI_INT, result,
222                                          count, MPI_INT, TARGET, 0,
223                                          count, MPI_INT, MPI_SUM, win, &req );
224                    );
225
226         MPI_Win_free( &win );
227         MTestFreeComm(&comm);
228     }
229
230     MPI_Type_free(&derived_dtp);
231
232     free( result );
233     free( buf );
234     free( rmabuf );
235     MTest_Finalize( errs );
236     MPI_Finalize();
237     return 0;
238 }