Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icscatterv.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 scatterv test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *buf = 0;
21     int *sendcounts;
22     int *senddispls;
23     int leftGroup, i, count, rank, rsize, size;
24     MPI_Comm comm;
25     MPI_Datatype datatype;
26
27     MTest_Init(&argc, &argv);
28
29     datatype = MPI_INT;
30     /* Get an intercommunicator */
31     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
32         if (comm == MPI_COMM_NULL)
33             continue;
34         MPI_Comm_remote_size(comm, &rsize);
35         MPI_Comm_rank(comm, &rank);
36         MPI_Comm_size(comm, &size);
37
38         /* To improve reporting of problems about operations, we
39          * change the error handler to errors return */
40         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
41
42         for (count = 1; count < 65000; count = 2 * count) {
43             buf = 0;
44             sendcounts = (int *) malloc(rsize * sizeof(int));
45             senddispls = (int *) malloc(rsize * sizeof(int));
46             for (i = 0; i < rsize; i++) {
47                 sendcounts[i] = count;
48                 senddispls[i] = count * i;
49             }
50             if (leftGroup) {
51                 buf = (int *) malloc(count * rsize * sizeof(int));
52                 if (rank == 0) {
53                     for (i = 0; i < count * rsize; i++)
54                         buf[i] = i;
55                 }
56                 else {
57                     for (i = 0; i < count * rsize; i++)
58                         buf[i] = -1;
59                 }
60                 err = MTest_Scatterv(buf, sendcounts, senddispls, datatype,
61                                      NULL, 0, datatype,
62                                      (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
63                 if (err) {
64                     errs++;
65                     MTestPrintError(err);
66                 }
67                 /* Test that no other process in this group received the
68                  * scatter */
69                 if (rank != 0) {
70                     for (i = 0; i < count * rsize; i++) {
71                         if (buf[i] != -1) {
72                             if (errs < 10) {
73                                 fprintf(stderr, "Received data on root group!\n");
74                             }
75                             errs++;
76                         }
77                     }
78                 }
79             }
80             else {
81                 buf = (int *) malloc(count * sizeof(int));
82                 /* In the right group */
83                 for (i = 0; i < count; i++)
84                     buf[i] = -1;
85                 err = MTest_Scatterv(NULL, 0, 0, datatype, buf, count, datatype, 0, comm);
86                 if (err) {
87                     errs++;
88                     MTestPrintError(err);
89                 }
90                 /* Check that we have received the correct data */
91                 for (i = 0; i < count; i++) {
92                     if (buf[i] != i + rank * count) {
93                         if (errs < 10)
94                             fprintf(stderr, "buf[%d] = %d on %d\n", i, buf[i], rank);
95                         errs++;
96                     }
97                 }
98             }
99             free(sendcounts);
100             free(senddispls);
101             free(buf);
102         }
103         MTestFreeComm(&comm);
104     }
105
106     MTest_Finalize(errs);
107     MPI_Finalize();
108     return 0;
109 }