1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
3 * (C) 2012 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
13 * Test user-defined operations with a large number of elements.
14 * Added because a talk at EuroMPI'12 claimed that these failed with
15 * more than 64k elements
19 #define MAX_COUNT 1200000
21 void myop( void *cinPtr, void *coutPtr, int *count, MPI_Datatype *dtype );
24 * myop takes a datatype that is a triple of doubles, and computes
25 * the sum, max, min of the respective elements of the triple.
27 void myop( void *cinPtr, void *coutPtr, int *count, MPI_Datatype *dtype )
30 double const *cin = (double *)cinPtr;
31 double *cout = (double *)coutPtr;
35 cout[1] = (cout[1] > cin[1]) ? cout[1] : cin[1];
36 cout[2] = (cout[2] < cin[2]) ? cout[2] : cin[2];
42 int main( int argc, char *argv[] )
45 int wsize, wrank, i, count;
46 MPI_Datatype tripleType;
47 double *inVal, *outVal;
48 double maxval, sumval;
51 MTest_Init( &argc, &argv );
52 MPI_Op_create( myop, 0, &op );
53 MPI_Type_contiguous( 3, MPI_DOUBLE, &tripleType );
54 MPI_Type_commit( &tripleType );
56 MPI_Comm_size( MPI_COMM_WORLD, &wsize );
57 MPI_Comm_rank( MPI_COMM_WORLD, &wrank );
59 for (count=1; count<MAX_COUNT; count += count) {
61 MTestPrintfMsg( 1, "Count = %d\n", count );
62 inVal = (double *)malloc( 3 * count * sizeof(double) );
63 outVal = (double *)malloc( 3 * count * sizeof(double) );
64 if (!inVal || !outVal) {
65 fprintf( stderr, "Unable to allocated %d words for data\n",
67 MPI_Abort( MPI_COMM_WORLD, 1 );
69 for (i=0; i<count*3; i++) {
71 inVal[i] = 1 + (i & 0x3);
73 MPI_Reduce( inVal, outVal, count, tripleType, op, 0, MPI_COMM_WORLD );
74 /* Check Result values */
76 for (i=0; i<3*count; i+=3) {
77 sumval = wsize * (1 + (i & 0x3));
78 maxval = 1 + ((i+1) & 0x3);
79 if (outVal[i] != sumval) {
81 fprintf( stderr, "%d: outval[%d] = %f, expected %f (sum)\n",
82 count, i, outVal[i], sumval );
85 if (outVal[i+1] != maxval) {
87 fprintf( stderr, "%d: outval[%d] = %f, expected %f (max)\n",
88 count, i+1, outVal[i+1], maxval );
91 if (outVal[i+2] != 1 + ((i+2)&0x3)) {
93 fprintf( stderr, "%d: outval[%d] = %f, expected %f (min)\n",
94 count, i+2, outVal[i+2], (double)(1 + ((i+2)^0x3)) );
105 MPI_Type_free( &tripleType );
106 MTest_Finalize( errs );