Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
support MPI_Op_commutative call, as it was already implemented internally
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / opminloc.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 "mpitestconf.h"
9 #include <stdio.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test MPI_MINLOC operations on datatypes dupported by MPICH";
14 */
15
16 /*
17  * This test looks at the handling of char and types that  are not required
18  * integers (e.g., long long).  MPICH allows
19  * these as well.  A strict MPI test should not include this test.
20  *
21  * The rule on min loc is that if there is a tie in the value, the minimum
22  * rank is used (see 4.9.3 in the MPI-1 standard)
23  */
24 int main(int argc, char *argv[])
25 {
26     int errs = 0;
27     int rank, size;
28     MPI_Comm comm;
29
30     MTest_Init(&argc, &argv);
31
32     comm = MPI_COMM_WORLD;
33
34     MPI_Comm_rank(comm, &rank);
35     MPI_Comm_size(comm, &size);
36
37     /* 2 int */
38     {
39         struct twoint {
40             int val;
41             int loc;
42         } cinbuf[3], coutbuf[3];
43
44         cinbuf[0].val = 1;
45         cinbuf[0].loc = rank;
46         cinbuf[1].val = 0;
47         cinbuf[1].loc = rank;
48         cinbuf[2].val = (rank & 0x7f);
49         cinbuf[2].loc = rank;
50
51         coutbuf[0].val = 0;
52         coutbuf[0].loc = -1;
53         coutbuf[1].val = 1;
54         coutbuf[1].loc = -1;
55         coutbuf[2].val = 1;
56         coutbuf[2].loc = -1;
57         MPI_Reduce(cinbuf, coutbuf, 3, MPI_2INT, MPI_MINLOC, 0, comm);
58         if (rank == 0) {
59             if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
60                 errs++;
61                 fprintf(stderr, "2int MINLOC(1) test failed\n");
62             }
63             if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
64                 errs++;
65                 fprintf(stderr, "2int MINLOC(0) test failed\n");
66             }
67             if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
68                 errs++;
69                 fprintf(stderr, "2int MINLOC(>) test failed\n");
70             }
71         }
72     }
73
74     /* float int */
75     {
76         struct floatint {
77             float val;
78             int loc;
79         } cinbuf[3], coutbuf[3];
80
81         cinbuf[0].val = 1;
82         cinbuf[0].loc = rank;
83         cinbuf[1].val = 0;
84         cinbuf[1].loc = rank;
85         cinbuf[2].val = (float) rank;
86         cinbuf[2].loc = rank;
87
88         coutbuf[0].val = 0;
89         coutbuf[0].loc = -1;
90         coutbuf[1].val = 1;
91         coutbuf[1].loc = -1;
92         coutbuf[2].val = 1;
93         coutbuf[2].loc = -1;
94         MPI_Reduce(cinbuf, coutbuf, 3, MPI_FLOAT_INT, MPI_MINLOC, 0, comm);
95         if (rank == 0) {
96             if (coutbuf[0].val != 1 && coutbuf[0].loc != -1) {
97                 errs++;
98                 fprintf(stderr, "float-int MINLOC(1) test failed\n");
99             }
100             if (coutbuf[1].val != 0 && coutbuf[1].loc != -1) {
101                 errs++;
102                 fprintf(stderr, "float-int MINLOC(0) test failed\n");
103             }
104             if (coutbuf[2].val != 0 && coutbuf[2].loc != 0) {
105                 errs++;
106                 fprintf(stderr, "float-int MINLOC(>) test failed\n");
107             }
108         }
109     }
110
111     /* long int */
112     {
113         struct longint {
114             long val;
115             int loc;
116         } cinbuf[3], coutbuf[3];
117
118         cinbuf[0].val = 1;
119         cinbuf[0].loc = rank;
120         cinbuf[1].val = 0;
121         cinbuf[1].loc = rank;
122         cinbuf[2].val = rank;
123         cinbuf[2].loc = rank;
124
125         coutbuf[0].val = 0;
126         coutbuf[0].loc = -1;
127         coutbuf[1].val = 1;
128         coutbuf[1].loc = -1;
129         coutbuf[2].val = 1;
130         coutbuf[2].loc = -1;
131         MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_INT, MPI_MINLOC, 0, comm);
132         if (rank == 0) {
133             if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
134                 errs++;
135                 fprintf(stderr, "long-int MINLOC(1) test failed\n");
136             }
137             if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
138                 errs++;
139                 fprintf(stderr, "long-int MINLOC(0) test failed\n");
140             }
141             if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
142                 errs++;
143                 fprintf(stderr, "long-int MINLOC(>) test failed\n");
144             }
145         }
146     }
147
148     /* short int */
149     {
150         struct shortint {
151             short val;
152             int loc;
153         } cinbuf[3], coutbuf[3];
154
155         cinbuf[0].val = 1;
156         cinbuf[0].loc = rank;
157         cinbuf[1].val = 0;
158         cinbuf[1].loc = rank;
159         cinbuf[2].val = rank;
160         cinbuf[2].loc = rank;
161
162         coutbuf[0].val = 0;
163         coutbuf[0].loc = -1;
164         coutbuf[1].val = 1;
165         coutbuf[1].loc = -1;
166         coutbuf[2].val = 1;
167         coutbuf[2].loc = -1;
168         MPI_Reduce(cinbuf, coutbuf, 3, MPI_SHORT_INT, MPI_MINLOC, 0, comm);
169         if (rank == 0) {
170             if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
171                 errs++;
172                 fprintf(stderr, "short-int MINLOC(1) test failed\n");
173             }
174             if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
175                 errs++;
176                 fprintf(stderr, "short-int MINLOC(0) test failed\n");
177             }
178             if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
179                 errs++;
180                 fprintf(stderr, "short-int MINLOC(>) test failed\n");
181             }
182         }
183     }
184
185     /* double int */
186     {
187         struct doubleint {
188             double val;
189             int loc;
190         } cinbuf[3], coutbuf[3];
191
192         cinbuf[0].val = 1;
193         cinbuf[0].loc = rank;
194         cinbuf[1].val = 0;
195         cinbuf[1].loc = rank;
196         cinbuf[2].val = rank;
197         cinbuf[2].loc = rank;
198
199         coutbuf[0].val = 0;
200         coutbuf[0].loc = -1;
201         coutbuf[1].val = 1;
202         coutbuf[1].loc = -1;
203         coutbuf[2].val = 1;
204         coutbuf[2].loc = -1;
205         MPI_Reduce(cinbuf, coutbuf, 3, MPI_DOUBLE_INT, MPI_MINLOC, 0, comm);
206         if (rank == 0) {
207             if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
208                 errs++;
209                 fprintf(stderr, "double-int MINLOC(1) test failed\n");
210             }
211             if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
212                 errs++;
213                 fprintf(stderr, "double-int MINLOC(0) test failed\n");
214             }
215             if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
216                 errs++;
217                 fprintf(stderr, "double-int MINLOC(>) test failed\n");
218             }
219         }
220     }
221
222 #ifdef HAVE_LONG_DOUBLE
223     /* long double int */
224     {
225         struct longdoubleint {
226             long double val;
227             int loc;
228         } cinbuf[3], coutbuf[3];
229         MTEST_VG_MEM_INIT(cinbuf, 3* sizeof(cinbuf[0]));
230
231         cinbuf[0].val = 1;
232         cinbuf[0].loc = rank;
233         cinbuf[1].val = 0;
234         cinbuf[1].loc = rank;
235         cinbuf[2].val = rank;
236         cinbuf[2].loc = rank;
237
238         coutbuf[0].val = 0;
239         coutbuf[0].loc = -1;
240         coutbuf[1].val = 1;
241         coutbuf[1].loc = -1;
242         coutbuf[2].val = 1;
243         coutbuf[2].loc = -1;
244         if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
245             MPI_Reduce(cinbuf, coutbuf, 3, MPI_LONG_DOUBLE_INT, MPI_MINLOC, 0, comm);
246             if (rank == 0) {
247                 if (coutbuf[0].val != 1 || coutbuf[0].loc != 0) {
248                     errs++;
249                     fprintf(stderr, "long double-int MINLOC(1) test failed\n");
250                 }
251                 if (coutbuf[1].val != 0 || coutbuf[1].loc != 0) {
252                     errs++;
253                     fprintf(stderr, "long double-int MINLOC(0) test failed\n");
254                 }
255                 if (coutbuf[2].val != 0 || coutbuf[2].loc != 0) {
256                     errs++;
257                     fprintf(stderr, "long double-int MINLOC(>) test failed\n");
258                 }
259             }
260         }
261     }
262 #endif
263
264     MTest_Finalize(errs);
265     MPI_Finalize();
266     return 0;
267 }