Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll10.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include "mpitest.h"
9
10 #define BAD_ANSWER 100000
11
12 int assoc ( int *, int *, int *, MPI_Datatype * );
13
14 /*
15     The operation is inoutvec[i] = invec[i] op inoutvec[i] 
16     (see 4.9.4).  The order is important.
17
18     Note that the computation is in process rank (in the communicator)
19     order, independant of the root.
20  */
21 int assoc(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype)
22 {
23   int i;
24   for ( i=0; i<*len; i++ )  {
25     if (inoutvec[i] <= invec[i] ) {
26       int rank;
27       MPI_Comm_rank( MPI_COMM_WORLD, &rank );
28       fprintf( stderr, "[%d] inout[0] = %d, in[0] = %d\n", 
29                rank, inoutvec[0], invec[0] );
30       inoutvec[i] = BAD_ANSWER;
31       }
32     else 
33       inoutvec[i] = invec[i];
34   }
35   return (1);
36 }
37
38 int main( int argc, char **argv )
39 {
40     int              rank, size;
41     int              data;
42     int              errors=0;
43     int              result = -100;
44     MPI_Op           op;
45
46     MTest_Init( &argc, &argv );
47     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
48     MPI_Comm_size( MPI_COMM_WORLD, &size );
49
50     data = rank;
51
52     MPI_Op_create( (MPI_User_function*)assoc, 0, &op );
53     MPI_Reduce ( &data, &result, 1, MPI_INT, op, size-1, MPI_COMM_WORLD );
54     MPI_Bcast  ( &result, 1, MPI_INT, size-1, MPI_COMM_WORLD );
55     MPI_Op_free( &op );
56     if (result == BAD_ANSWER) errors++;
57
58     MTest_Finalize( errors );
59     MPI_Finalize();
60     return MTestReturnValue( errors );
61 }