Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Upgrade coll mpich testlist to new mpich
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icscatter.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 scatter test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *buf = 0;
21     int leftGroup, i, count, rank, size, 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         MPI_Comm_remote_size(comm, &rsize);
33         MPI_Comm_rank(comm, &rank);
34         MPI_Comm_size(comm, &size);
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             buf = 0;
42             if (leftGroup) {
43                 buf = (int *) malloc(count * rsize * sizeof(int));
44                 if (rank == 0) {
45                     for (i = 0; i < count * rsize; i++)
46                         buf[i] = i;
47                 }
48                 else {
49                     for (i = 0; i < count * rsize; i++)
50                         buf[i] = -1;
51                 }
52                 err = MTest_Scatter(buf, count, datatype,
53                                     NULL, 0, datatype,
54                                     (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
55                 if (err) {
56                     errs++;
57                     MTestPrintError(err);
58                 }
59                 /* Test that no other process in this group received the
60                  * scatter */
61                 if (rank != 0) {
62                     for (i = 0; i < count * rsize; i++) {
63                         if (buf[i] != -1) {
64                             if (errs < 10) {
65                                 fprintf(stderr, "Received data on root group!\n");
66                             }
67                             errs++;
68                         }
69                     }
70                 }
71             }
72             else {
73                 buf = (int *) malloc(count * sizeof(int));
74                 /* In the right group */
75                 for (i = 0; i < count; i++)
76                     buf[i] = -1;
77                 err = MTest_Scatter(NULL, 0, datatype, buf, count, datatype, 0, comm);
78                 if (err) {
79                     errs++;
80                     MTestPrintError(err);
81                 }
82                 /* Check that we have received the correct data */
83                 for (i = 0; i < count; i++) {
84                     if (buf[i] != i + rank * count) {
85                         if (errs < 10)
86                             fprintf(stderr, "buf[%d] = %d on %d\n", i, buf[i], rank);
87                         errs++;
88                     }
89                 }
90             }
91             free(buf);
92         }
93         MTestFreeComm(&comm);
94     }
95
96     MTest_Finalize(errs);
97     MPI_Finalize();
98     return 0;
99 }