Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
support MPI_Op_commutative call, as it was already implemented internally
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icreduce.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 #include "mpicolltest.h"
12
13 /*
14 static char MTEST_Descrip[] = "Simple intercomm reduce test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *sendbuf = 0, *recvbuf = 0;
21     int leftGroup, i, count, rank, rsize;
22     MPI_Comm comm;
23     MPI_Datatype datatype;
24
25     MTest_Init(&argc, &argv);
26
27     datatype = MPI_INT;
28     /* Get an intercommunicator */
29     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
30         if (comm == MPI_COMM_NULL)
31             continue;
32
33         MPI_Comm_rank(comm, &rank);
34         MPI_Comm_remote_size(comm, &rsize);
35
36         /* To improve reporting of problems about operations, we
37          * change the error handler to errors return */
38         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
39
40         for (count = 1; count < 65000; count = 2 * count) {
41             sendbuf = (int *) malloc(count * sizeof(int));
42             recvbuf = (int *) malloc(count * sizeof(int));
43             for (i = 0; i < count; i++) {
44                 sendbuf[i] = -1;
45                 recvbuf[i] = -1;
46             }
47             if (leftGroup) {
48                 err = MTest_Reduce(sendbuf, recvbuf, count, datatype, MPI_SUM,
49                                    (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
50                 if (err) {
51                     errs++;
52                     MTestPrintError(err);
53                 }
54                 /* Test that no other process in this group received the
55                  * broadcast, and that we got the right answers */
56                 if (rank == 0) {
57                     for (i = 0; i < count; i++) {
58                         if (recvbuf[i] != i * rsize) {
59                             errs++;
60                         }
61                     }
62                 }
63                 else {
64                     for (i = 0; i < count; i++) {
65                         if (recvbuf[i] != -1) {
66                             errs++;
67                         }
68                     }
69                 }
70             }
71             else {
72                 /* In the right group */
73                 for (i = 0; i < count; i++)
74                     sendbuf[i] = i;
75                 err = MTest_Reduce(sendbuf, recvbuf, count, datatype, MPI_SUM, 0, comm);
76                 if (err) {
77                     errs++;
78                     MTestPrintError(err);
79                 }
80                 /* Check that we have received no data */
81                 for (i = 0; i < count; i++) {
82                     if (recvbuf[i] != -1) {
83                         errs++;
84                     }
85                 }
86             }
87             free(sendbuf);
88             free(recvbuf);
89         }
90         MTestFreeComm(&comm);
91     }
92
93     MTest_Finalize(errs);
94     MPI_Finalize();
95     return 0;
96 }