Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[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)
28             continue;
29         /* Determine the sender and receiver */
30         MPI_Comm_rank(comm, &rank);
31         MPI_Comm_size(comm, &size);
32
33         for (count = 1; count < 130000; count = count * 2) {
34             sendbuf = (int *) malloc(count * sizeof(int));
35             recvbuf = (int *) malloc(count * sizeof(int));
36             for (root = 0; root < size; root++) {
37                 for (i = 0; i < count; i++)
38                     sendbuf[i] = i;
39                 for (i = 0; i < count; i++)
40                     recvbuf[i] = -1;
41                 MPI_Reduce(sendbuf, recvbuf, count, MPI_INT, MPI_SUM, root, comm);
42                 if (rank == root) {
43                     for (i = 0; i < count; i++) {
44                         if (recvbuf[i] != i * size) {
45                             errs++;
46                         }
47                     }
48                 }
49             }
50             free(sendbuf);
51             free(recvbuf);
52         }
53         MTestFreeComm(&comm);
54     }
55
56     MTest_Finalize(errs);
57     MPI_Finalize();
58     return 0;
59 }