Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
49252548b8bf454fae6b394f7350f6be2b97b7b9
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll9.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4
5 void addem ( int *, int *, int *, MPI_Datatype * );
6
7 void addem(invec, inoutvec, len, dtype)
8 int *invec, *inoutvec, *len;
9 MPI_Datatype *dtype;
10 {
11   int i;
12   for ( i=0; i<*len; i++ ) 
13     inoutvec[i] += invec[i];
14 }
15
16 int main( int argc, char **argv )
17 {
18     int              rank, size, i;
19     int              data;
20     int              errors=0;
21     int              result = -100;
22     int              correct_result;
23     MPI_Op           op;
24
25     MPI_Init( &argc, &argv );
26     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
27     MPI_Comm_size( MPI_COMM_WORLD, &size );
28
29     data = rank;
30     MPI_Op_create( (MPI_User_function *)addem, 1, &op );
31     MPI_Reduce ( &data, &result, 1, MPI_INT, op, 0, MPI_COMM_WORLD );
32     MPI_Bcast  ( &result, 1, MPI_INT, 0, MPI_COMM_WORLD );
33     MPI_Op_free( &op );
34     correct_result = 0;
35     for(i=0;i<size;i++) 
36       correct_result += i;
37     if (result != correct_result) errors++;
38
39     Test_Waitforall( );
40     MPI_Finalize();
41     if (errors)
42       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
43     return errors;
44 }