Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll9.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 void addem ( int *, int *, int *, MPI_Datatype * );
11
12 void addem(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype)
13 {
14   int i;
15   for ( i=0; i<*len; i++ ) 
16     inoutvec[i] += invec[i];
17 }
18
19 int main( int argc, char **argv )
20 {
21     int              rank, size, i;
22     int              data;
23     int              errors=0;
24     int              result = -100;
25     int              correct_result;
26     MPI_Op           op;
27
28     MTest_Init( &argc, &argv );
29     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
30     MPI_Comm_size( MPI_COMM_WORLD, &size );
31
32     data = rank;
33     MPI_Op_create( (MPI_User_function *)addem, 1, &op );
34     MPI_Reduce ( &data, &result, 1, MPI_INT, op, 0, MPI_COMM_WORLD );
35     MPI_Bcast  ( &result, 1, MPI_INT, 0, MPI_COMM_WORLD );
36     MPI_Op_free( &op );
37     correct_result = 0;
38     for(i=0;i<size;i++) 
39       correct_result += i;
40     if (result != correct_result) errors++;
41
42     MTest_Finalize( errors );
43     MPI_Finalize();
44     return MTestReturnValue( errors );
45 }