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_BAND operations on optional datatypes dupported by MPICH";
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.
21 int main( int argc, char *argv[] )
27 char cinbuf[3], coutbuf[3];
28 signed char scinbuf[3], scoutbuf[3];
29 unsigned char ucinbuf[3], ucoutbuf[3];
30 short sinbuf[3], soutbuf[3];
31 unsigned short usinbuf[3], usoutbuf[3];
32 long linbuf[3], loutbuf[3];
33 unsigned long ulinbuf[3], uloutbuf[3];
34 unsigned uinbuf[3], uoutbuf[3];
37 MTest_Init( &argc, &argv );
39 comm = MPI_COMM_WORLD;
40 /* Set errors return so that we can provide better information
41 should a routine reject one of the operand/datatype pairs */
42 MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
44 MPI_Comm_rank( comm, &rank );
45 MPI_Comm_size( comm, &size );
47 #ifndef USE_STRICT_MPI
49 MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
52 cinbuf[2] = (rank > 0) ? 0xff : 0xf0;
57 rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_BAND, 0, comm );
59 MTestPrintErrorMsg( "MPI_BAND and MPI_CHAR", rc );
64 if (coutbuf[0] != (char)0xff) {
66 fprintf( stderr, "char BAND(1) test failed\n" );
70 fprintf( stderr, "char BAND(0) test failed\n" );
72 if (coutbuf[2] != (char)0xf0 && size > 1) {
74 fprintf( stderr, "char BAND(>) test failed\n" );
78 #endif /* USE_STRICT_MPI */
81 MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
84 scinbuf[2] = (rank > 0) ? 0xff : 0xf0;
89 rc = MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_BAND, 0, comm );
91 MTestPrintErrorMsg( "MPI_BAND and MPI_SIGNED_CHAR", rc );
96 if (scoutbuf[0] != (signed char)0xff) {
98 fprintf( stderr, "signed char BAND(1) test failed\n" );
102 fprintf( stderr, "signed char BAND(0) test failed\n" );
104 if (scoutbuf[2] != (signed char)0xf0 && size > 1) {
106 fprintf( stderr, "signed char BAND(>) test failed\n" );
112 MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
115 ucinbuf[2] = (rank > 0) ? 0xff : 0xf0;
120 rc = MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_BAND, 0, comm );
122 MTestPrintErrorMsg( "MPI_BAND and MPI_UNSIGNED_CHAR", rc );
127 if (ucoutbuf[0] != 0xff) {
129 fprintf( stderr, "unsigned char BAND(1) test failed\n" );
133 fprintf( stderr, "unsigned char BAND(0) test failed\n" );
135 if (ucoutbuf[2] != 0xf0 && size > 1) {
137 fprintf( stderr, "unsigned char BAND(>) test failed\n" );
143 MTestPrintfMsg( 10, "Reduce of MPI_BYTE\n" );
146 cinbuf[2] = (rank > 0) ? 0xff : 0xf0;
151 rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_BYTE, MPI_BAND, 0, comm );
153 MTestPrintErrorMsg( "MPI_BAND and MPI_BYTE", rc );
158 if (coutbuf[0] != (char)0xff) {
160 fprintf( stderr, "byte BAND(1) test failed\n" );
164 fprintf( stderr, "byte BAND(0) test failed\n" );
166 if (coutbuf[2] != (char)0xf0 && size > 1) {
168 fprintf( stderr, "byte BAND(>) test failed\n" );
174 MTestPrintfMsg( 10, "Reduce of MPI_SHORT\n" );
177 sinbuf[2] = (rank > 0) ? 0xffff : 0xf0f0;
182 rc = MPI_Reduce( sinbuf, soutbuf, 3, MPI_SHORT, MPI_BAND, 0, comm );
184 MTestPrintErrorMsg( "MPI_BAND and MPI_SHORT", rc );
189 if (soutbuf[0] != (short)0xffff) {
191 fprintf( stderr, "short BAND(1) test failed\n" );
195 fprintf( stderr, "short BAND(0) test failed\n" );
197 if (soutbuf[2] != (short)0xf0f0 && size > 1) {
199 fprintf( stderr, "short BAND(>) test failed\n" );
204 MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_SHORT\n" );
208 usinbuf[2] = (rank > 0) ? 0xffff : 0xf0f0;
213 rc = MPI_Reduce( usinbuf, usoutbuf, 3, MPI_UNSIGNED_SHORT, MPI_BAND, 0, comm );
215 MTestPrintErrorMsg( "MPI_BAND and MPI_UNSIGNED_SHORT", rc );
220 if (usoutbuf[0] != 0xffff) {
222 fprintf( stderr, "short BAND(1) test failed\n" );
226 fprintf( stderr, "short BAND(0) test failed\n" );
228 if (usoutbuf[2] != 0xf0f0 && size > 1) {
230 fprintf( stderr, "short BAND(>) test failed\n" );
236 MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED\n" );
237 uinbuf[0] = 0xffffffff;
239 uinbuf[2] = (rank > 0) ? 0xffffffff : 0xf0f0f0f0;
244 rc = MPI_Reduce( uinbuf, uoutbuf, 3, MPI_UNSIGNED, MPI_BAND, 0, comm );
246 MTestPrintErrorMsg( "MPI_BAND and MPI_UNSIGNED", rc );
251 if (uoutbuf[0] != 0xffffffff) {
253 fprintf( stderr, "unsigned BAND(1) test failed\n" );
257 fprintf( stderr, "unsigned BAND(0) test failed\n" );
259 if (uoutbuf[2] != 0xf0f0f0f0 && size > 1) {
261 fprintf( stderr, "unsigned BAND(>) test failed\n" );
267 MTestPrintfMsg( 10, "Reduce of MPI_LONG\n" );
268 linbuf[0] = 0xffffffff;
270 linbuf[2] = (rank > 0) ? 0xffffffff : 0xf0f0f0f0;
275 rc = MPI_Reduce( linbuf, loutbuf, 3, MPI_LONG, MPI_BAND, 0, comm );
277 MTestPrintErrorMsg( "MPI_BAND and MPI_LONG", rc );
282 if (loutbuf[0] != 0xffffffff) {
284 fprintf( stderr, "long BAND(1) test failed\n" );
288 fprintf( stderr, "long BAND(0) test failed\n" );
290 if (loutbuf[2] != 0xf0f0f0f0 && size > 1) {
292 fprintf( stderr, "long BAND(>) test failed\n" );
297 MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_LONG\n" );
299 ulinbuf[0] = 0xffffffff;
301 ulinbuf[2] = (rank > 0) ? 0xffffffff : 0xf0f0f0f0;
306 rc = MPI_Reduce( ulinbuf, uloutbuf, 3, MPI_UNSIGNED_LONG, MPI_BAND, 0, comm );
308 MTestPrintErrorMsg( "MPI_BAND and MPI_UNSIGNED_LONG", rc );
313 if (uloutbuf[0] != 0xffffffff) {
315 fprintf( stderr, "unsigned long BAND(1) test failed\n" );
319 fprintf( stderr, "unsigned long BAND(0) test failed\n" );
321 if (uloutbuf[2] != 0xf0f0f0f0 && size > 1) {
323 fprintf( stderr, "unsigned long BAND(>) test failed\n" );
328 #ifdef HAVE_LONG_LONG
330 long long llinbuf[3], lloutbuf[3];
332 llinbuf[0] = 0xffffffff;
334 llinbuf[2] = (rank > 0) ? 0xffffffff : 0xf0f0f0f0;
339 if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
340 MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
341 rc = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_BAND, 0, comm );
343 MTestPrintErrorMsg( "MPI_BAND and MPI_LONG_LONG", rc );
348 if (lloutbuf[0] != 0xffffffff) {
350 fprintf( stderr, "long long BAND(1) test failed\n" );
354 fprintf( stderr, "long long BAND(0) test failed\n" );
356 if (lloutbuf[2] != 0xf0f0f0f0 && size > 1) {
358 fprintf( stderr, "long long BAND(>) test failed\n" );
366 MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
367 MTest_Finalize( errs );