1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
8 #include "mpitestconf.h"
13 static char MTEST_Descrip[] = "Test MPI_SUM operations on optional datatypes dupported by MPICH";
16 typedef struct { double r, i; } d_complex;
17 #ifdef HAVE_LONG_DOUBLE
18 typedef struct { long double r, i; } ld_complex;
22 * This test looks at the handling of logical and for types that are not
23 * integers or are not required integers (e.g., long long). MPICH allows
24 * these as well. A strict MPI test should not include this test.
26 int main( int argc, char *argv[] )
31 char cinbuf[3], coutbuf[3];
32 signed char scinbuf[3], scoutbuf[3];
33 unsigned char ucinbuf[3], ucoutbuf[3];
34 d_complex dinbuf[3], doutbuf[3];
36 MTest_Init( &argc, &argv );
38 comm = MPI_COMM_WORLD;
40 MPI_Comm_rank( comm, &rank );
41 MPI_Comm_size( comm, &size );
43 #ifndef USE_STRICT_MPI
45 MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
48 cinbuf[2] = (rank > 0);
53 MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_SUM, 0, comm );
55 if (size < 128 && coutbuf[0] != size) {
57 fprintf( stderr, "char SUM(1) test failed\n" );
59 if (size < 128 && coutbuf[1] != 0) {
61 fprintf( stderr, "char SUM(0) test failed\n" );
63 if (size < 128 && coutbuf[2] != size - 1) {
65 fprintf( stderr, "char SUM(>) test failed\n" );
68 #endif /* USE_MPI_STRICT */
71 MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
74 scinbuf[2] = (rank > 0);
79 MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_SUM, 0, comm );
81 if (size < 128 && scoutbuf[0] != size) {
83 fprintf( stderr, "signed char SUM(1) test failed\n" );
85 if (size < 128 && scoutbuf[1] != 0) {
87 fprintf( stderr, "signed char SUM(0) test failed\n" );
89 if (size < 128 && scoutbuf[2] != size - 1) {
91 fprintf( stderr, "signed char SUM(>) test failed\n" );
96 MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
99 ucinbuf[2] = (rank > 0);
104 MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_SUM, 0, comm );
106 if (size < 128 && ucoutbuf[0] != size) {
108 fprintf( stderr, "unsigned char SUM(1) test failed\n" );
110 if (size < 128 && ucoutbuf[1]) {
112 fprintf( stderr, "unsigned char SUM(0) test failed\n" );
114 if (size < 128 && ucoutbuf[2] != size - 1) {
116 fprintf( stderr, "unsigned char SUM(>) test failed\n" );
120 #ifndef USE_STRICT_MPI
121 /* For some reason, complex is not allowed for sum and prod */
122 if (MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
124 #ifdef HAVE_LONG_DOUBLE
125 ld_complex ldinbuf[3], ldoutbuf[3];
127 /* Must determine which C type matches this Fortran type */
128 MPI_Type_size( MPI_DOUBLE_COMPLEX, &dc );
129 if (dc == sizeof(d_complex)) {
130 MTestPrintfMsg( 10, "Reduce of MPI_DOUBLE_COMPLEX\n" );
131 /* double complex; may be null if we do not have Fortran support */
134 dinbuf[2].r = (rank > 0);
137 dinbuf[2].i = -(rank > 0);
145 MPI_Reduce( dinbuf, doutbuf, 3, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm );
147 if (doutbuf[0].r != size || doutbuf[0].i != -size) {
149 fprintf( stderr, "double complex SUM(1) test failed\n" );
151 if (doutbuf[1].r != 0 || doutbuf[1].i != 0) {
153 fprintf( stderr, "double complex SUM(0) test failed\n" );
155 if (doutbuf[2].r != size - 1 || doutbuf[2].i != 1 - size) {
157 fprintf( stderr, "double complex SUM(>) test failed\n" );
161 #ifdef HAVE_LONG_DOUBLE
162 else if (dc == sizeof(ld_complex)) {
163 MTestPrintfMsg( 10, "Reduce of MPI_DOUBLE_COMPLEX\n" );
164 /* double complex; may be null if we do not have Fortran support */
167 ldinbuf[2].r = (rank > 0);
170 ldinbuf[2].i = -(rank > 0);
178 MPI_Reduce( ldinbuf, ldoutbuf, 3, MPI_DOUBLE_COMPLEX,
181 if (ldoutbuf[0].r != size || ldoutbuf[0].i != -size) {
183 fprintf( stderr, "double complex SUM(1) test failed\n" );
185 if (ldoutbuf[1].r != 0 || ldoutbuf[1].i != 0) {
187 fprintf( stderr, "double complex SUM(0) test failed\n" );
189 if (ldoutbuf[2].r != size - 1 || ldoutbuf[2].i != 1 - size) {
191 fprintf( stderr, "double complex SUM(>) test failed\n" );
196 /* Implicitly ignore if there is no matching C type */
198 #endif /* USE_STRICT_MPI */
200 #ifdef HAVE_LONG_DOUBLE
201 { long double ldinbuf[3], ldoutbuf[3];
205 ldinbuf[2] = (rank > 0);
210 if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
211 MTestPrintfMsg( 10, "Reduce of MPI_LONG_DOUBLE\n" );
212 MPI_Reduce( ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_SUM, 0, comm );
214 if (ldoutbuf[0] != size) {
216 fprintf( stderr, "long double SUM(1) test failed\n" );
218 if (ldoutbuf[1] != 0.0) {
220 fprintf( stderr, "long double SUM(0) test failed\n" );
222 if (ldoutbuf[2] != size - 1) {
224 fprintf( stderr, "long double SUM(>) test failed\n" );
231 #ifdef HAVE_LONG_LONG
233 long long llinbuf[3], lloutbuf[3];
237 llinbuf[2] = (rank > 0);
242 if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
243 MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
244 MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_SUM, 0, comm );
246 if (lloutbuf[0] != size) {
248 fprintf( stderr, "long long SUM(1) test failed\n" );
250 if (lloutbuf[1] != 0) {
252 fprintf( stderr, "long long SUM(0) test failed\n" );
254 if (lloutbuf[2] != size - 1) {
256 fprintf( stderr, "long long SUM(>) test failed\n" );
263 MTest_Finalize( errs );