Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / opmin.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_MIN operations on optional 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 int main(int argc, char *argv[])
22 {
23     int errs = 0;
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
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 #ifndef USE_STRICT_MPI
38     /* char */
39     MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
40     cinbuf[0] = 1;
41     cinbuf[1] = 0;
42     cinbuf[2] = (rank & 0x7f);
43
44     coutbuf[0] = 0;
45     coutbuf[1] = 1;
46     coutbuf[2] = 1;
47     MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_MIN, 0, comm);
48     if (rank == 0) {
49         if (coutbuf[0] != 1) {
50             errs++;
51             fprintf(stderr, "char MIN(1) test failed\n");
52         }
53         if (coutbuf[1] != 0) {
54             errs++;
55             fprintf(stderr, "char MIN(0) test failed\n");
56         }
57         if (coutbuf[2] != 0) {
58             errs++;
59             fprintf(stderr, "char MIN(>) test failed\n");
60         }
61     }
62 #endif /* USE_STRICT_MPI */
63
64     /* signed char */
65     MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
66     scinbuf[0] = 1;
67     scinbuf[1] = 0;
68     scinbuf[2] = (rank & 0x7f);
69
70     scoutbuf[0] = 0;
71     scoutbuf[1] = 1;
72     scoutbuf[2] = 1;
73     MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_MIN, 0, comm);
74     if (rank == 0) {
75         if (scoutbuf[0] != 1) {
76             errs++;
77             fprintf(stderr, "signed char MIN(1) test failed\n");
78         }
79         if (scoutbuf[1] != 0) {
80             errs++;
81             fprintf(stderr, "signed char MIN(0) test failed\n");
82         }
83         if (scoutbuf[2] != 0) {
84             errs++;
85             fprintf(stderr, "signed char MIN(>) test failed\n");
86         }
87     }
88
89     /* unsigned char */
90     MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
91     ucinbuf[0] = 1;
92     ucinbuf[1] = 0;
93     ucinbuf[2] = (rank & 0x7f);
94
95     ucoutbuf[0] = 0;
96     ucoutbuf[1] = 1;
97     ucoutbuf[2] = 1;
98     MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_MIN, 0, comm);
99     if (rank == 0) {
100         if (ucoutbuf[0] != 1) {
101             errs++;
102             fprintf(stderr, "unsigned char MIN(1) test failed\n");
103         }
104         if (ucoutbuf[1]) {
105             errs++;
106             fprintf(stderr, "unsigned char MIN(0) test failed\n");
107         }
108         if (ucoutbuf[2] != 0) {
109             errs++;
110             fprintf(stderr, "unsigned char MIN(>) test failed\n");
111         }
112     }
113
114 #ifdef HAVE_LONG_DOUBLE
115     {
116         long double ldinbuf[3], ldoutbuf[3];
117         /* long double */
118         MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
119         ldinbuf[0] = 1;
120         ldinbuf[1] = 0;
121         ldinbuf[2] = rank;
122
123         ldoutbuf[0] = 0;
124         ldoutbuf[1] = 1;
125         ldoutbuf[2] = 1;
126         if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
127             MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
128             MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_MIN, 0, comm);
129             if (rank == 0) {
130                 if (ldoutbuf[0] != 1) {
131                     errs++;
132                     fprintf(stderr, "long double MIN(1) test failed\n");
133                 }
134                 if (ldoutbuf[1] != 0.0) {
135                     errs++;
136                     fprintf(stderr, "long double MIN(0) test failed\n");
137                 }
138                 if (ldoutbuf[2] != 0.0) {
139                     errs++;
140                     fprintf(stderr, "long double MIN(>) test failed\n");
141                 }
142             }
143         }
144     }
145 #endif /* HAVE_LONG_DOUBLE */
146
147 #ifdef HAVE_LONG_LONG
148     {
149         long long llinbuf[3], lloutbuf[3];
150         /* long long */
151         llinbuf[0] = 1;
152         llinbuf[1] = 0;
153         llinbuf[2] = rank;
154
155         lloutbuf[0] = 0;
156         lloutbuf[1] = 1;
157         lloutbuf[2] = 1;
158         if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
159             MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
160             MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_MIN, 0, comm);
161             if (rank == 0) {
162                 if (lloutbuf[0] != 1) {
163                     errs++;
164                     fprintf(stderr, "long long MIN(1) test failed\n");
165                 }
166                 if (lloutbuf[1] != 0) {
167                     errs++;
168                     fprintf(stderr, "long long MIN(0) test failed\n");
169                 }
170                 if (lloutbuf[2] != 0) {
171                     errs++;
172                     fprintf(stderr, "long long MIN(>) test failed\n");
173                 }
174             }
175         }
176     }
177 #endif /* HAVE_LONG_LONG */
178
179     MTest_Finalize(errs);
180     MPI_Finalize();
181     return 0;
182 }