Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / allred2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test MPI_Allreduce with MPI_IN_PLACE";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size;
20     int minsize = 2, count; 
21     MPI_Comm      comm;
22     int *buf, i;
23
24     MTest_Init( &argc, &argv );
25
26     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
27         if (comm == MPI_COMM_NULL) continue;
28         MPI_Comm_size( comm, &size );
29         MPI_Comm_rank( comm, &rank );
30         
31         for (count = 1; count < 65000; count = count * 2) {
32             /* Contiguous data */
33             buf = (int *)malloc( count * sizeof(int) );
34             for (i=0; i<count; i++) buf[i] = rank + i;
35             MPI_Allreduce( MPI_IN_PLACE, buf, count, MPI_INT, MPI_SUM, comm );
36             /* Check the results */
37             for (i=0; i<count; i++) {
38                 int result = i * size + (size*(size-1))/2;
39                 if (buf[i] != result) {
40                     errs ++;
41                     if (errs < 10) {
42                         fprintf( stderr, "buf[%d] = %d expected %d\n",
43                                  i, buf[i], result );
44                     }
45                 }
46             }
47             free( buf );
48         }
49         MTestFreeComm( &comm );
50     }
51
52     MTest_Finalize( errs );
53     MPI_Finalize();
54     return 0;
55 }