Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Upgrade coll mpich testlist to new mpich
[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)
28             continue;
29         MPI_Comm_size(comm, &size);
30         MPI_Comm_rank(comm, &rank);
31
32         for (count = 1; count < 65000; count = count * 2) {
33             /* Contiguous data */
34             buf = (int *) malloc(count * sizeof(int));
35             for (i = 0; i < count; i++)
36                 buf[i] = rank + i;
37             MPI_Allreduce(MPI_IN_PLACE, buf, count, MPI_INT, MPI_SUM, comm);
38             /* Check the results */
39             for (i = 0; i < count; i++) {
40                 int result = i * size + (size * (size - 1)) / 2;
41                 if (buf[i] != result) {
42                     errs++;
43                     if (errs < 10) {
44                         fprintf(stderr, "buf[%d] = %d expected %d\n", i, buf[i], result);
45                     }
46                 }
47             }
48             free(buf);
49         }
50         MTestFreeComm(&comm);
51     }
52
53     MTest_Finalize(errs);
54     MPI_Finalize();
55     return 0;
56 }