Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e14503f3b1cf7a357c3582ad1c1762f25bc49e0c
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / gather.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 */
14
15 int main( int argc, char **argv )
16 {
17     MPI_Datatype vec;
18     MPI_Comm     comm;
19     double *vecin, *vecout;
20     int    minsize = 2, count;
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) continue;
28         /* Determine the sender and receiver */
29         MPI_Comm_rank( comm, &rank );
30         MPI_Comm_size( comm, &size );
31         
32         for (root=0; root<size; root++) {
33             for (count = 1; count < 65000; count = count * 2) {
34                 n = 12;
35                 stride = 10;
36                 vecin = (double *)malloc( n * stride * size * sizeof(double) );
37                 vecout = (double *)malloc( size * n * sizeof(double) );
38                 
39                 MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec );
40                 MPI_Type_commit( &vec );
41                 
42                 for (i=0; i<n*stride; i++) vecin[i] =-2;
43                 for (i=0; i<n; i++) vecin[i*stride] = rank * n + i;
44                 
45                 MPI_Gather( vecin, 1, vec, vecout, n, MPI_DOUBLE, root, comm );
46                 
47                 if (rank == root) {
48                     for (i=0; i<n*size; i++) {
49                         if (vecout[i] != i) {
50                             errs++;
51                             if (errs < 10) {
52                                 fprintf( stderr, "vecout[%d]=%d\n",
53                                          i, (int)vecout[i] );
54                             }
55                         }
56                     }
57                 }
58                 MPI_Type_free( &vec );
59                 free( vecin );
60                 free( vecout );
61             }
62         }
63         MTestFreeComm( &comm );
64     }
65
66     /* do a zero length gather */
67     MPI_Gather( NULL, 0, MPI_BYTE, NULL, 0, MPI_BYTE, 0, MPI_COMM_WORLD );
68
69 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
70     /* Check to make sure that aliasing is disallowed correctly */
71     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
72     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
73     if (0 == rank)
74         if (MPI_SUCCESS == MPI_Gather(&rank, 1, MPI_INT,
75                                       &rank, 1, MPI_INT, 0, MPI_COMM_WORLD))
76             errs++;
77 #endif
78
79     MTest_Finalize( errs );
80     MPI_Finalize();
81     return 0;
82 }
83
84