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 / icgather.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 gather 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, rsize, size;
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_rank(comm, &rank);
33         MPI_Comm_remote_size(comm, &rsize);
34         MPI_Comm_size(comm, &size);
35         /* To improve reporting of problems about operations, we
36          * change the error handler to errors return */
37         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
38         for (count = 1; count < 65000; count = 2 * count) {
39             if (leftGroup) {
40                 buf = (int *) malloc(count * rsize * sizeof(int));
41                 for (i = 0; i < count * rsize; i++)
42                     buf[i] = -1;
43
44                 err = MTest_Gather(NULL, 0, datatype,
45                                    buf, count, datatype,
46                                    (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
47                 if (err) {
48                     errs++;
49                     MTestPrintError(err);
50                 }
51                 /* Test that no other process in this group received the
52                  * broadcast */
53                 if (rank != 0) {
54                     for (i = 0; i < count; i++) {
55                         if (buf[i] != -1) {
56                             errs++;
57                         }
58                     }
59                 }
60                 else {
61                     /* Check for the correct data */
62                     for (i = 0; i < count * rsize; i++) {
63                         if (buf[i] != i) {
64                             errs++;
65                         }
66                     }
67                 }
68             }
69             else {
70                 /* In the right group */
71                 buf = (int *) malloc(count * sizeof(int));
72                 for (i = 0; i < count; i++)
73                     buf[i] = rank * count + i;
74                 err = MTest_Gather(buf, count, datatype, NULL, 0, datatype, 0, comm);
75                 if (err) {
76                     errs++;
77                     MTestPrintError(err);
78                 }
79             }
80             free(buf);
81         }
82         MTestFreeComm(&comm);
83     }
84
85     MTest_Finalize(errs);
86     MPI_Finalize();
87     return 0;
88 }