Logo AND Algorithmique Numérique Distribuée

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