Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update collectives teshsuite from mpich git (only minor changes)
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / allgatherv2.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.  This is 
14    the trivial version based on the allgather test (allgatherv but with
15    constant data sizes) */
16
17 int main( int argc, char **argv )
18 {
19     double *vecout;
20     MPI_Comm comm;
21     int    count, minsize = 2;
22     int    i, errs = 0;
23     int    rank, size;
24     int    *displs, *recvcounts;
25
26     MTest_Init( &argc, &argv );
27
28     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
29         if (comm == MPI_COMM_NULL) continue;
30         /* Determine the sender and receiver */
31         MPI_Comm_rank( comm, &rank );
32         MPI_Comm_size( comm, &size );
33
34         displs     = (int *)malloc( size * sizeof(int) );
35         recvcounts = (int *)malloc( size * sizeof(int) );
36         
37         for (count = 1; count < 9000; count = count * 2) {
38             vecout = (double *)malloc( size * count * sizeof(double) );
39             
40             for (i=0; i<count; i++) {
41                 vecout[rank*count+i] = rank*count+i;
42             }
43             for (i=0; i<size; i++) {
44                 recvcounts[i] = count;
45                 displs[i]    = i * count;
46             }
47             MPI_Allgatherv( MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 
48                             vecout, recvcounts, displs, MPI_DOUBLE, comm );
49             for (i=0; i<count*size; i++) {
50                 if (vecout[i] != i) {
51                     errs++;
52                     if (errs < 10) {
53                         fprintf( stderr, "vecout[%d]=%d\n",
54                                  i, (int)vecout[i] );
55                     }
56                 }
57             }
58             free( vecout );
59         }
60
61 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
62         MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
63         vecout = (double *) malloc(size * sizeof(double));
64         if (MPI_SUCCESS == MPI_Allgatherv(&vecout[rank * recvcounts[rank]], recvcounts[rank], MPI_DOUBLE,
65                                            vecout, recvcounts, displs, MPI_DOUBLE, comm))
66             errs++;
67         free(vecout);
68 #endif
69
70         free( displs );
71         free( recvcounts );
72         MTestFreeComm( &comm );
73     }
74     
75     MTest_Finalize( errs );
76     MPI_Finalize();
77     return 0;
78 }
79
80