Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[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) 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                 int errorcode = MPI_SUCCESS;
45                 if (rank == root) {
46                     for (i=0; i<n; i++) {
47                         vecout[rank*n+i] = rank*n+i;
48                     }
49                     errorcode = MPI_Gather( MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 
50                                 vecout, n, MPI_DOUBLE, root, comm );
51                 }
52                 else {
53                     errorcode = MPI_Gather( vecin, 1, vec, NULL, -1, MPI_DATATYPE_NULL, 
54                                 root, comm );
55                 }
56
57                 if (rank == root) {
58                     for (i=0; i<n*size; i++) {
59                         if (vecout[i] != i) {
60                             errs++;
61                             if (errs < 10) {
62                                 fprintf( stderr, "vecout[%d]=%d, err=%d\n",
63                                          i, (int)vecout[i], errorcode );
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,
80                     MPI_COMM_WORLD );
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 }
89
90