6 int add ( double *, double *, int *, MPI_Datatype * );
8 * User-defined operation on a long value (tests proper handling of
9 * possible pipelining in the implementation of reductions with user-defined
12 int add( invec, inoutvec, len, dtype )
13 double *invec, *inoutvec;
19 inoutvec[i] = invec[i] + inoutvec[i];
24 int main( int argc, char **argv )
27 int i, rank, size, bufsize, errcnt = 0, toterr;
28 double *inbuf, *outbuf, value;
30 MPI_Init( &argc, &argv );
31 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
32 MPI_Comm_size( MPI_COMM_WORLD, &size );
33 MPI_Op_create( (MPI_User_function *)add, 1, &op );
36 while (bufsize < 100000) {
37 inbuf = (double *)malloc( bufsize * sizeof(double) );
38 outbuf = (double *)malloc( bufsize * sizeof(double) );
39 if (! inbuf || ! outbuf) {
40 fprintf( stderr, "Could not allocate buffers for size %d\n",
46 value = (rank & 0x1) ? 1.0 : -1.0;
47 for (i=0; i<bufsize; i++) {
51 MPI_Allreduce( inbuf, outbuf, bufsize, MPI_DOUBLE, op,
54 value = (size & 0x1) ? -1.0 : 0.0;
55 for (i=0; i<bufsize; i++) {
56 if (outbuf[i] != value) {
58 printf( "outbuf[%d] = %f, should = %f\n", i, outbuf[i],
68 MPI_Allreduce( &errcnt, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
69 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
72 printf( " No Errors\n" );
74 printf( "*! %d errors!\n", toterr );