Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / gather2.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
8 #include "mpi.h"
9 #include "mpitest.h"
10 #include <stdlib.h>
11 #include <stdio.h>
12
13 /* Gather data from a vector to contiguous.  Use IN_PLACE */
14
15 int main(int argc, char **argv)
16 {
17     MPI_Datatype vec;
18     double *vecin, *vecout;
19     MPI_Comm comm;
20     int count, minsize = 2;
21     int root, i, n, stride, errs = 0;
22     int rank, size;
23
24     MTest_Init(&argc, &argv);
25
26     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
27         if (comm == MPI_COMM_NULL)
28             continue;
29         /* Determine the sender and receiver */
30         MPI_Comm_rank(comm, &rank);
31         MPI_Comm_size(comm, &size);
32
33         for (root = 0; root < size; root++) {
34             for (count = 1; count < 65000; count = count * 2) {
35                 n = 12;
36                 stride = 10;
37                 vecin = (double *) malloc(n * stride * size * sizeof(double));
38                 vecout = (double *) malloc(size * n * sizeof(double));
39
40                 MPI_Type_vector(n, 1, stride, MPI_DOUBLE, &vec);
41                 MPI_Type_commit(&vec);
42
43                 for (i = 0; i < n * stride; i++)
44                     vecin[i] = -2;
45                 for (i = 0; i < n; i++)
46                     vecin[i * stride] = rank * n + i;
47
48                 if (rank == root) {
49                     for (i = 0; i < n; i++) {
50                         vecout[rank * n + i] = rank * n + i;
51                     }
52                     MPI_Gather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL,
53                                vecout, n, MPI_DOUBLE, root, comm);
54                 }
55                 else {
56                     MPI_Gather(vecin, 1, vec, NULL, -1, MPI_DATATYPE_NULL, root, comm);
57                 }
58                 if (rank == root) {
59                     for (i = 0; i < n * size; i++) {
60                         if (vecout[i] != i) {
61                             errs++;
62                             if (errs < 10) {
63                                 fprintf(stderr, "vecout[%d]=%d\n", i, (int) vecout[i]);
64                             }
65                         }
66                     }
67                 }
68                 MPI_Type_free(&vec);
69                 free(vecin);
70                 free(vecout);
71             }
72         }
73         MTestFreeComm(&comm);
74     }
75
76     /* do a zero length gather */
77     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
78     if (rank == 0) {
79         MPI_Gather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, NULL, 0, MPI_BYTE, 0, MPI_COMM_WORLD);
80     }
81     else {
82         MPI_Gather(NULL, 0, MPI_BYTE, NULL, 0, MPI_BYTE, 0, MPI_COMM_WORLD);
83     }
84
85     MTest_Finalize(errs);
86     MPI_Finalize();
87     return 0;
88 }