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 );
70 for (i=0; i<count*3; i++) {
72 inVal[i] = 1 + (i & 0x3);
74 MPI_Reduce( inVal, outVal, count, tripleType, op, 0, MPI_COMM_WORLD );
75 /* Check Result values */
77 for (i=0; i<3*count; i+=3) {
78 sumval = wsize * (1 + (i & 0x3));
79 maxval = 1 + ((i+1) & 0x3);
80 if (outVal[i] != sumval) {
82 fprintf( stderr, "%d: outval[%d] = %f, expected %f (sum)\n",
83 count, i, outVal[i], sumval );
86 if (outVal[i+1] != maxval) {
88 fprintf( stderr, "%d: outval[%d] = %f, expected %f (max)\n",
89 count, i+1, outVal[i+1], maxval );
92 if (outVal[i+2] != 1 + ((i+2)&0x3)) {
94 fprintf( stderr, "%d: outval[%d] = %f, expected %f (min)\n",
95 count, i+2, outVal[i+2], (double)(1 + ((i+2)^0x3)) );
106 MPI_Type_free( &tripleType );
107 MTest_Finalize( errs );