1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 int add ( double *, double *, int *, MPI_Datatype * );
12 * User-defined operation on a long value (tests proper handling of
13 * possible pipelining in the implementation of reductions with user-defined
16 int add( double *invec, double *inoutvec, int *len, MPI_Datatype *dtype )
20 inoutvec[i] = invec[i] + inoutvec[i];
25 int main( int argc, char **argv )
28 int i, rank, size, bufsize, errcnt = 0, toterr;
29 double *inbuf, *outbuf, value;
31 MPI_Init( &argc, &argv );
32 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
33 MPI_Comm_size( MPI_COMM_WORLD, &size );
34 MPI_Op_create( (MPI_User_function *)add, 1, &op );
37 while (bufsize < 100000) {
38 inbuf = (double *)malloc( bufsize * sizeof(double) );
39 outbuf = (double *)malloc( bufsize * sizeof(double) );
40 if (! inbuf || ! outbuf) {
41 fprintf( stderr, "Could not allocate buffers for size %d\n",
47 value = (rank & 0x1) ? 1.0 : -1.0;
48 for (i=0; i<bufsize; i++) {
52 MPI_Allreduce( inbuf, outbuf, bufsize, MPI_DOUBLE, op,
55 value = (size & 0x1) ? -1.0 : 0.0;
56 for (i=0; i<bufsize; i++) {
57 if (outbuf[i] != value) {
59 printf( "outbuf[%d] = %f, should = %f\n", i, outbuf[i],
69 MPI_Allreduce( &errcnt, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
70 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
73 printf( " No Errors\n" );
75 printf( "*! %d errors!\n", toterr );