Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll10.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4 #define BAD_ANSWER 100000
5
6 int assoc ( int *, int *, int *, MPI_Datatype * );
7
8 /*
9     The operation is inoutvec[i] = invec[i] op inoutvec[i] 
10     (see 4.9.4).  The order is important.
11
12     Note that the computation is in process rank (in the communicator)
13     order, independant of the root.
14  */
15 int assoc(invec, inoutvec, len, dtype)
16 int *invec, *inoutvec, *len;
17 MPI_Datatype *dtype;
18 {
19   int i;
20   for ( i=0; i<*len; i++ )  {
21     if (inoutvec[i] <= invec[i] ) {
22       int rank;
23       MPI_Comm_rank( MPI_COMM_WORLD, &rank );
24       fprintf( stderr, "[%d] inout[0] = %d, in[0] = %d\n", 
25                rank, inoutvec[0], invec[0] );
26       inoutvec[i] = BAD_ANSWER;
27       }
28     else 
29       inoutvec[i] = invec[i];
30   }
31   return (1);
32 }
33
34 int main( int argc, char **argv )
35 {
36     int              rank, size;
37     int              data;
38     int              errors=0;
39     int              result = -100;
40     MPI_Op           op;
41
42     MPI_Init( &argc, &argv );
43     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
44     MPI_Comm_size( MPI_COMM_WORLD, &size );
45
46     data = rank;
47
48     MPI_Op_create( (MPI_User_function*)assoc, 0, &op );
49     MPI_Reduce ( &data, &result, 1, MPI_INT, op, size-1, MPI_COMM_WORLD );
50     MPI_Bcast  ( &result, 1, MPI_INT, size-1, MPI_COMM_WORLD );
51     MPI_Op_free( &op );
52     if (result == BAD_ANSWER) errors++;
53
54     if (errors)
55       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
56     Test_Waitforall( );
57     MPI_Finalize();
58
59     return errors;
60 }