Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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) continue;
134         /* Determine the sender and receiver */
135         MPI_Comm_rank( comm, &rank );
136         MPI_Comm_size( comm, &size );
137         
138         MPI_Win_create( buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win );
139         /* To improve reporting of problems about operations, we
140            change the error handler to errors return */
141         MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
142
143         /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
144         MPI_Win_fence( 0, win );
145
146         TEST_FENCE_OP("Put",
147                       MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
148                                rcount, MPI_INT, win );
149                      );
150
151         TEST_FENCE_OP("Get",
152                       MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
153                                rcount, MPI_INT, win );
154                      );
155         TEST_FENCE_OP("Accumulate",
156                       MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL,
157                                       0, rcount, MPI_INT, MPI_SUM, win );
158                      );
159         TEST_FENCE_OP("Get accumulate",
160                       MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result,
161                                           rcount, MPI_INT, MPI_PROC_NULL, 0,
162                                           rcount, MPI_INT, MPI_SUM, win );
163                      );
164         TEST_FENCE_OP("Fetch and op",
165                       MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL,
166                                         0, MPI_SUM, win );
167                      );
168         TEST_FENCE_OP("Compare and swap",
169                       MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT,
170                                             MPI_PROC_NULL, 0, win );
171                      );
172
173         /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
174
175         TEST_PT_OP("Put",
176                    MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
177                             MPI_INT, win );
178                    );
179         TEST_PT_OP("Get",
180                    MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
181                             MPI_INT, win );
182                    );
183         TEST_PT_OP("Accumulate",
184                    MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
185                                    rcount, MPI_INT, MPI_SUM, win );
186                    );
187         TEST_PT_OP("Get accumulate",
188                    MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result, rcount,
189                                        MPI_INT, MPI_PROC_NULL, 0, rcount,
190                                        MPI_INT, MPI_SUM, win );
191                    );
192         TEST_PT_OP("Fetch and op",
193                    MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL, 0,
194                                      MPI_SUM, win );
195                    );
196         TEST_PT_OP("Compare and swap",
197                    MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT,
198                                          MPI_PROC_NULL, 0, win );
199                    );
200
201         /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
202
203         TEST_REQ_OP("Rput", req,
204                     MPI_Rput( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
205                               MPI_INT, win, &req );
206                    );
207         TEST_REQ_OP("Rget", req,
208                     MPI_Rget( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
209                               MPI_INT, win, &req );
210                    );
211         TEST_REQ_OP("Raccumulate", req,
212                     MPI_Raccumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
213                                      rcount, MPI_INT, MPI_SUM, win, &req );
214                    );
215         TEST_REQ_OP("Rget_accumulate", req,
216                     MPI_Rget_accumulate( rmabuf, rcount, MPI_INT, result,
217                                          rcount, MPI_INT, MPI_PROC_NULL, 0,
218                                          rcount, MPI_INT, MPI_SUM, win, &req );
219                    );
220
221         MPI_Win_free( &win );
222         MTestFreeComm(&comm);
223     }
224
225     free( result );
226     free( buf );
227     free( rmabuf );
228     MTest_Finalize( errs );
229     MPI_Finalize();
230     return 0;
231 }