Logo AND Algorithmique Numérique Distribuée

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