Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / reduce.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[] = "A simple test of Reduce with all choices of root process";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size, root;
20     int *sendbuf, *recvbuf, i;
21     int minsize = 2, count; 
22     MPI_Comm      comm;
23
24     MTest_Init( &argc, &argv );
25
26     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
27         if (comm == MPI_COMM_NULL) continue;
28         /* Determine the sender and receiver */
29         MPI_Comm_rank( comm, &rank );
30         MPI_Comm_size( comm, &size );
31         
32         for (count = 1; count < 130000; count = count * 2) {
33             sendbuf = (int *)malloc( count * sizeof(int) );
34             recvbuf = (int *)malloc( count * sizeof(int) );
35             for (root = 0; root < size; root ++) {
36                 for (i=0; i<count; i++) sendbuf[i] = i;
37                 for (i=0; i<count; i++) recvbuf[i] = -1;
38                 MPI_Reduce( sendbuf, recvbuf, count, MPI_INT, MPI_SUM, 
39                             root, comm );
40                 if (rank == root) {
41                     for (i=0; i<count; i++) {
42                         if (recvbuf[i] != i * size) {
43                             errs++;
44                         }
45                     }
46                 }
47             }
48             free( sendbuf );
49             free( recvbuf );
50         }
51         MTestFreeComm( &comm );
52     }
53
54     MTest_Finalize( errs );
55     MPI_Finalize();
56     return 0;
57 }