Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This used to work by accident
[simgrid.git] / teshsuite / smpi / mpich-test / coll / allred2.c
1 /* 
2    This test checks for possible interference between 
3    successive calls to MPI_Allreduce.  Some users, on some MPI implementations
4    and platforms, have had to add MPI_Barrier before MPI_Allreduce calls.
5    */
6 #include "mpi.h"
7 #include <stdio.h>
8
9 #define MAX_LOOP 1000
10
11 int main( int argc, char *argv[] )
12 {
13     int i, in_val, out_val;
14     int rank, size;
15     int errs = 0, toterrs;
16
17     MPI_Init( &argc, &argv );
18
19     MPI_Comm_size( MPI_COMM_WORLD, &size );
20     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
21     for (i=0; i<MAX_LOOP; i++) {
22         in_val = (i & 0x1) ? 10 : -10;
23         MPI_Allreduce( &in_val, &out_val, 1, MPI_INT, MPI_SUM, 
24                        MPI_COMM_WORLD );
25         if (i & 0x1) {
26             if (out_val != 10 * size) {
27                 errs++;
28                 printf( "[%d] Error in out_val = %d\n", rank, out_val );
29             }
30         }
31         else {
32             if (-out_val != 10 * size) {
33                 errs++;
34                 printf( "[%d] Error in out_val = %d\n", rank, out_val );
35             }
36         }
37     }
38     MPI_Barrier( MPI_COMM_WORLD );
39     MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
40     
41     if (rank == 0) {
42         if (toterrs) 
43             printf( " Found %d errors\n", toterrs );
44         else
45             printf( " No Errors\n" );
46     }
47
48     MPI_Finalize( );
49     return 0;
50 }