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 / icgatherv.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 gatherv test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *buf = 0;
21     int *recvcounts;
22     int *recvdispls;
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     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
31         if (comm == MPI_COMM_NULL)
32             continue;
33         MPI_Comm_rank(comm, &rank);
34         MPI_Comm_remote_size(comm, &rsize);
35         MPI_Comm_size(comm, &size);
36
37         /* To improve reporting of problems about operations, we
38          * change the error handler to errors return */
39         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
40
41         for (count = 1; count < 65000; count = 2 * count) {
42             /* Get an intercommunicator */
43             recvcounts = (int *) malloc(rsize * sizeof(int));
44             recvdispls = (int *) malloc(rsize * sizeof(int));
45             /* This simple test duplicates the Gather test,
46              * using the same lengths for all messages */
47             for (i = 0; i < rsize; i++) {
48                 recvcounts[i] = count;
49                 recvdispls[i] = count * i;
50             }
51             if (leftGroup) {
52                 buf = (int *) malloc(count * rsize * sizeof(int));
53                 for (i = 0; i < count * rsize; i++)
54                     buf[i] = -1;
55
56                 err = MTest_Gatherv(NULL, 0, datatype,
57                                     buf, recvcounts, recvdispls, datatype,
58                                     (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
59                 if (err) {
60                     errs++;
61                     MTestPrintError(err);
62                 }
63                 /* Test that no other process in this group received the
64                  * broadcast */
65                 if (rank != 0) {
66                     for (i = 0; i < count; i++) {
67                         if (buf[i] != -1) {
68                             errs++;
69                         }
70                     }
71                 }
72                 else {
73                     /* Check for the correct data */
74                     for (i = 0; i < count * rsize; i++) {
75                         if (buf[i] != i) {
76                             errs++;
77                         }
78                     }
79                 }
80             }
81             else {
82                 /* In the right group */
83                 buf = (int *) malloc(count * sizeof(int));
84                 for (i = 0; i < count; i++)
85                     buf[i] = rank * count + i;
86                 err = MTest_Gatherv(buf, count, datatype, NULL, 0, 0, datatype, 0, comm);
87                 if (err) {
88                     errs++;
89                     MTestPrintError(err);
90                 }
91             }
92             free(buf);
93             free(recvcounts);
94             free(recvdispls);
95         }
96         MTestFreeComm(&comm);
97     }
98
99     MTest_Finalize(errs);
100     MPI_Finalize();
101     return 0;
102 }