Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / oplor.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_LOR operations on optional datatypes dupported by MPICH";
14 */
15
16 /*
17  * This test looks at the handling of logical and for types that are not
18  * integers or are not required integers (e.g., long long).  MPICH allows
19  * these as well.  A strict MPI test should not include this test.
20  */
21 int main(int argc, char *argv[])
22 {
23     int errs = 0, err;
24     int rank, size;
25     MPI_Comm comm;
26     char cinbuf[3], coutbuf[3];
27     signed char scinbuf[3], scoutbuf[3];
28     unsigned char ucinbuf[3], ucoutbuf[3];
29     float finbuf[3], foutbuf[3];
30     double dinbuf[3], doutbuf[3];
31
32     MTest_Init(&argc, &argv);
33
34     comm = MPI_COMM_WORLD;
35
36     MPI_Comm_rank(comm, &rank);
37     MPI_Comm_size(comm, &size);
38
39     /* Some MPI implementations do not implement all of the required
40      * (datatype,operations) combinations, and further, they do not
41      * always provide clear and specific error messages.  By catching
42      * the error, we can provide a higher quality, more specific message.
43      */
44     MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
45
46 #ifndef USE_STRICT_MPI
47     /* char */
48     MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
49     cinbuf[0] = 1;
50     cinbuf[1] = 0;
51     cinbuf[2] = (rank > 0);
52
53     coutbuf[0] = 0;
54     coutbuf[1] = 1;
55     coutbuf[2] = 1;
56     err = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_LOR, 0, comm);
57     if (err) {
58         errs++;
59         MTestPrintErrorMsg("MPI_LOR and MPI_CHAR", err);
60     }
61     else {
62         if (rank == 0) {
63             if (!coutbuf[0]) {
64                 errs++;
65                 fprintf(stderr, "char OR(1) test failed\n");
66             }
67             if (coutbuf[1]) {
68                 errs++;
69                 fprintf(stderr, "char OR(0) test failed\n");
70             }
71             if (!coutbuf[2] && size > 1) {
72                 errs++;
73                 fprintf(stderr, "char OR(>) test failed\n");
74             }
75         }
76     }
77 #endif /* USE_STRICT_MPI */
78
79     /* signed char */
80     MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
81     scinbuf[0] = 1;
82     scinbuf[1] = 0;
83     scinbuf[2] = (rank > 0);
84
85     scoutbuf[0] = 0;
86     scoutbuf[1] = 1;
87     scoutbuf[2] = 1;
88     err = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LOR, 0, comm);
89     if (err) {
90         errs++;
91         MTestPrintErrorMsg("MPI_LOR and MPI_SIGNED_CHAR", err);
92     }
93     else {
94         if (rank == 0) {
95             if (!scoutbuf[0]) {
96                 errs++;
97                 fprintf(stderr, "signed char OR(1) test failed\n");
98             }
99             if (scoutbuf[1]) {
100                 errs++;
101                 fprintf(stderr, "signed char OR(0) test failed\n");
102             }
103             if (!scoutbuf[2] && size > 1) {
104                 errs++;
105                 fprintf(stderr, "signed char OR(>) test failed\n");
106             }
107         }
108     }
109
110     /* unsigned char */
111     MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
112     ucinbuf[0] = 1;
113     ucinbuf[1] = 0;
114     ucinbuf[2] = (rank > 0);
115
116     ucoutbuf[0] = 0;
117     ucoutbuf[1] = 1;
118     ucoutbuf[2] = 1;
119     err = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LOR, 0, comm);
120     if (err) {
121         errs++;
122         MTestPrintErrorMsg("MPI_LOR and MPI_UNSIGNED_CHAR", err);
123     }
124     else {
125         if (rank == 0) {
126             if (!ucoutbuf[0]) {
127                 errs++;
128                 fprintf(stderr, "unsigned char OR(1) test failed\n");
129             }
130             if (ucoutbuf[1]) {
131                 errs++;
132                 fprintf(stderr, "unsigned char OR(0) test failed\n");
133             }
134             if (!ucoutbuf[2] && size > 1) {
135                 errs++;
136                 fprintf(stderr, "unsigned char OR(>) test failed\n");
137             }
138         }
139     }
140
141 #ifndef USE_STRICT_MPI
142     /* float */
143     MTestPrintfMsg(10, "Reduce of MPI_FLOAT\n");
144     finbuf[0] = 1;
145     finbuf[1] = 0;
146     finbuf[2] = (rank > 0);
147
148     foutbuf[0] = 0;
149     foutbuf[1] = 1;
150     foutbuf[2] = 1;
151     err = MPI_Reduce(finbuf, foutbuf, 3, MPI_FLOAT, MPI_LOR, 0, comm);
152     if (err) {
153         errs++;
154         MTestPrintErrorMsg("MPI_LOR and MPI_FLOAT", err);
155     }
156     else {
157         if (rank == 0) {
158             if (!foutbuf[0]) {
159                 errs++;
160                 fprintf(stderr, "float OR(1) test failed\n");
161             }
162             if (foutbuf[1]) {
163                 errs++;
164                 fprintf(stderr, "float OR(0) test failed\n");
165             }
166             if (!foutbuf[2] && size > 1) {
167                 errs++;
168                 fprintf(stderr, "float OR(>) test failed\n");
169             }
170         }
171     }
172
173     /* double */
174     MTestPrintfMsg(10, "Reduce of MPI_DOUBLE\n");
175     dinbuf[0] = 1;
176     dinbuf[1] = 0;
177     dinbuf[2] = (rank > 0);
178
179     doutbuf[0] = 0;
180     doutbuf[1] = 1;
181     doutbuf[2] = 1;
182     err = MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LOR, 0, comm);
183     if (err) {
184         errs++;
185         MTestPrintErrorMsg("MPI_LOR and MPI_DOUBLE", err);
186     }
187     else {
188         if (rank == 0) {
189             if (!doutbuf[0]) {
190                 errs++;
191                 fprintf(stderr, "double OR(1) test failed\n");
192             }
193             if (doutbuf[1]) {
194                 errs++;
195                 fprintf(stderr, "double OR(0) test failed\n");
196             }
197             if (!doutbuf[2] && size > 1) {
198                 errs++;
199                 fprintf(stderr, "double OR(>) test failed\n");
200             }
201         }
202     }
203
204 #ifdef HAVE_LONG_DOUBLE
205     {
206         long double ldinbuf[3], ldoutbuf[3];
207         /* long double */
208         MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
209         ldinbuf[0] = 1;
210         ldinbuf[1] = 0;
211         ldinbuf[2] = (rank > 0);
212
213         ldoutbuf[0] = 0;
214         ldoutbuf[1] = 1;
215         ldoutbuf[2] = 1;
216         if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
217             MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
218             err = MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LOR, 0, comm);
219             if (err) {
220                 errs++;
221                 MTestPrintErrorMsg("MPI_LOR and MPI_LONG_DOUBLE", err);
222             }
223             else {
224                 if (rank == 0) {
225                     if (!ldoutbuf[0]) {
226                         errs++;
227                         fprintf(stderr, "long double OR(1) test failed\n");
228                     }
229                     if (ldoutbuf[1]) {
230                         errs++;
231                         fprintf(stderr, "long double OR(0) test failed\n");
232                     }
233                     if (!ldoutbuf[2] && size > 1) {
234                         errs++;
235                         fprintf(stderr, "long double OR(>) test failed\n");
236                     }
237                 }
238             }
239         }
240     }
241 #endif /* HAVE_LONG_DOUBLE */
242 #endif /* USE_STRICT_MPI */
243
244 #ifdef HAVE_LONG_LONG
245     {
246         long long llinbuf[3], lloutbuf[3];
247         /* long long */
248         llinbuf[0] = 1;
249         llinbuf[1] = 0;
250         llinbuf[2] = (rank > 0);
251
252         lloutbuf[0] = 0;
253         lloutbuf[1] = 1;
254         lloutbuf[2] = 1;
255         if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
256             MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
257             err = MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LOR, 0, comm);
258             if (err) {
259                 errs++;
260                 MTestPrintErrorMsg("MPI_LOR and MPI_LONG_LONG", err);
261             }
262             else {
263                 if (rank == 0) {
264                     if (!lloutbuf[0]) {
265                         errs++;
266                         fprintf(stderr, "long long OR(1) test failed\n");
267                     }
268                     if (lloutbuf[1]) {
269                         errs++;
270                         fprintf(stderr, "long long OR(0) test failed\n");
271                     }
272                     if (!lloutbuf[2] && size > 1) {
273                         errs++;
274                         fprintf(stderr, "long long OR(>) test failed\n");
275                     }
276                 }
277             }
278         }
279     }
280 #endif
281
282     MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
283     MTest_Finalize(errs);
284     MPI_Finalize();
285     return 0;
286 }