Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
66389b5e13e92ecc0640a62cc89fd9b062ca4f38
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / allgather3.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     double *vecout, *invec;
18     MPI_Comm comm;
19     int    count, minsize = 2;
20     int    i, errs = 0;
21     int    rank, size;
22
23     MTest_Init( &argc, &argv );
24
25     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
26         if (comm == MPI_COMM_NULL) continue;
27         /* Determine the sender and receiver */
28         MPI_Comm_rank( comm, &rank );
29         MPI_Comm_size( comm, &size );
30         
31         for (count = 1; count < 9000; count = count * 2) {
32             invec = (double *)malloc( count * sizeof(double) );
33             vecout = (double *)malloc( size * count * sizeof(double) );
34             
35             for (i=0; i<count; i++) {
36                 invec[i] = rank*count+i;
37             }
38             MPI_Allgather( invec, count, MPI_DOUBLE, 
39                            vecout, count, MPI_DOUBLE, comm );
40             for (i=0; i<count*size; i++) {
41                 if (vecout[i] != i) {
42                     errs++;
43                     if (errs < 10) {
44                         fprintf( stderr, "vecout[%d]=%d\n",
45                                  i, (int)vecout[i] );
46                     }
47                 }
48             }
49             free( invec );
50             free( vecout );
51         }
52
53         MTestFreeComm( &comm );
54     }
55
56     /* Do a zero byte gather */
57     MPI_Allgather( MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, NULL, 0, MPI_BYTE, MPI_COMM_WORLD );
58
59     MTest_Finalize( errs );
60     MPI_Finalize();
61     return 0;
62 }
63
64