Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7ba9a66b6c2fda2028f04448a747fe981a864756
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / allgatherv3.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.  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, *invec;
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             invec = (double *)malloc( count * sizeof(double) );
39             vecout = (double *)malloc( size * count * sizeof(double) );
40             
41             for (i=0; i<count; i++) {
42                 invec[i] = rank*count+i;
43             }
44             for (i=0; i<size; i++) {
45                 recvcounts[i] = count;
46                 displs[i]    = i * count;
47             }
48             MPI_Allgatherv( invec, count, MPI_DOUBLE, 
49                             vecout, recvcounts, displs, MPI_DOUBLE, comm );
50             for (i=0; i<count*size; i++) {
51                 if (vecout[i] != i) {
52                     errs++;
53                     if (errs < 10) {
54                         fprintf( stderr, "vecout[%d]=%d\n",
55                                  i, (int)vecout[i] );
56                     }
57                 }
58             }
59             free( invec );
60             free( vecout );
61         }
62         free( displs );
63         free( recvcounts );
64         MTestFreeComm( &comm );
65     }
66     
67     MTest_Finalize( errs );
68     MPI_Finalize();
69     return 0;
70 }
71
72