Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[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     { long double ldinbuf[3], ldoutbuf[3];
116     /* long double */
117     ldinbuf[0] = 1;
118     ldinbuf[1] = 0;
119     ldinbuf[2] = rank;
120
121     ldoutbuf[0] = 0;
122     ldoutbuf[1] = 1;
123     ldoutbuf[2] = 1;
124     if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
125         MTestPrintfMsg( 10, "Reduce of MPI_LONG_DOUBLE\n" );
126         MPI_Reduce( ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_MIN, 0, comm );
127         if (rank == 0) {
128             if (ldoutbuf[0] != 1) {
129                 errs++;
130                 fprintf( stderr, "long double MIN(1) test failed\n" );
131             }
132             if (ldoutbuf[1] != 0.0) {
133                 errs++;
134                 fprintf( stderr, "long double MIN(0) test failed\n" );
135             }
136             if (ldoutbuf[2] != 0.0) {
137                 errs++;
138                 fprintf( stderr, "long double MIN(>) test failed\n" );
139             }
140         }
141     }
142     }
143 #endif /* HAVE_LONG_DOUBLE */
144
145 #ifdef HAVE_LONG_LONG
146     {
147         long long llinbuf[3], lloutbuf[3];
148     /* long long */
149     llinbuf[0] = 1;
150     llinbuf[1] = 0;
151     llinbuf[2] = rank;
152
153     lloutbuf[0] = 0;
154     lloutbuf[1] = 1;
155     lloutbuf[2] = 1;
156     if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
157         MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
158         MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_MIN, 0, comm );
159         if (rank == 0) {
160             if (lloutbuf[0] != 1) {
161                 errs++;
162                 fprintf( stderr, "long long MIN(1) test failed\n" );
163             }
164             if (lloutbuf[1] != 0) {
165                 errs++;
166                 fprintf( stderr, "long long MIN(0) test failed\n" );
167             }
168             if (lloutbuf[2] != 0) {
169                 errs++;
170                 fprintf( stderr, "long long MIN(>) test failed\n" );
171             }
172         }
173     }
174     }
175 #endif /* HAVE_LONG_LONG */
176
177     MTest_Finalize( errs );
178     MPI_Finalize();
179     return 0;
180 }