Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
66a21eca6ee8d9ce1bfee1ca54b25ebb8c88d9c6
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / allgather2.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     double *vecout;
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             vecout = (double *)malloc( size * count * sizeof(double) );
33             
34             for (i=0; i<count; i++) {
35                 vecout[rank*count+i] = rank*count+i;
36             }
37             MPI_Allgather( MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 
38                            vecout, count, MPI_DOUBLE, comm );
39             for (i=0; i<count*size; i++) {
40                 if (vecout[i] != i) {
41                     errs++;
42                     if (errs < 10) {
43                         fprintf( stderr, "vecout[%d]=%d\n",
44                                  i, (int)vecout[i] );
45                     }
46                 }
47             }
48             free( vecout );
49         }
50
51         MTestFreeComm( &comm );
52     }
53
54 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
55     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
56     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
57     MPI_Comm_size(MPI_COMM_WORLD, &size);
58     vecout = (double *) malloc(size * sizeof(double));
59     if (MPI_SUCCESS == MPI_Allgather(&vecout[rank], 1, MPI_DOUBLE,
60                                       vecout, 1, MPI_DOUBLE, MPI_COMM_WORLD))
61         errs++;
62     free(vecout);
63 #endif
64
65     MTest_Finalize( errs );
66     MPI_Finalize();
67     return 0;
68 }
69
70