Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icalltoallv.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include "mpitest.h"
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 /*
12   This program tests MPI_Alltoallv by having processor i send different
13   amounts of data to each processor.
14
15   Because there are separate send and receive types to alltoallv,
16   there need to be tests to rearrange data on the fly.  Not done yet.
17   
18   The first test sends i items to processor i from all processors.
19
20   Currently, the test uses only MPI_INT; this is adequate for testing systems
21   that use point-to-point operations
22  */
23
24 int main( int argc, char **argv )
25 {
26     MPI_Comm comm;
27     int      *sbuf, *rbuf;
28     int      rank, size, lsize, asize;
29     int      *sendcounts, *recvcounts, *rdispls, *sdispls;
30     int      i, j, *p, err;
31     int      leftGroup;
32
33     MTest_Init( &argc, &argv );
34     err = 0;
35
36     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
37       if (comm == MPI_COMM_NULL) continue;
38
39       /* Create the buffer */
40       MPI_Comm_size( comm, &lsize );
41       MPI_Comm_remote_size( comm, &size );
42       asize = (lsize > size) ? lsize : size;
43       MPI_Comm_rank( comm, &rank );
44       sbuf = (int *)malloc( size * size * sizeof(int) );
45       rbuf = (int *)malloc( asize * asize * sizeof(int) );
46       if (!sbuf || !rbuf) {
47         fprintf( stderr, "Could not allocated buffers!\n" );
48         MPI_Abort( comm, 1 );
49         exit(1);
50       }
51
52       /* Load up the buffers */
53       for (i=0; i<size*size; i++) {
54         sbuf[i] = i + 100*rank;
55         rbuf[i] = -i;
56       }
57
58       /* Create and load the arguments to alltoallv */
59       sendcounts = (int *)malloc( size * sizeof(int) );
60       recvcounts = (int *)malloc( size * sizeof(int) );
61       rdispls    = (int *)malloc( size * sizeof(int) );
62       sdispls    = (int *)malloc( size * sizeof(int) );
63       if (!sendcounts || !recvcounts || !rdispls || !sdispls) {
64         fprintf( stderr, "Could not allocate arg items!\n" );
65         MPI_Abort( comm, 1 );
66         exit(1);
67       }
68       for (i=0; i<size; i++) {
69         sendcounts[i] = i;
70         sdispls[i]    = (i * (i+1))/2;
71         recvcounts[i] = rank;
72         rdispls[i] = i * rank;
73       }
74       MPI_Alltoallv( sbuf, sendcounts, sdispls, MPI_INT,
75                      rbuf, recvcounts, rdispls, MPI_INT, comm );
76
77       /* Check rbuf */
78       for (i=0; i<size; i++) {
79         p = rbuf + rdispls[i];
80         for (j=0; j<rank; j++) {
81           if (p[j] != i * 100 + (rank*(rank+1))/2 + j) {
82             fprintf( stderr, "[%d] got %d expected %d for %dth\n",
83                      rank, p[j],(i*(i+1))/2 + j, j );
84             err++;
85           }
86         }
87       }
88
89       free( sdispls );
90       free( rdispls );
91       free( recvcounts );
92       free( sendcounts );
93       free( rbuf );
94       free( sbuf );
95       MTestFreeComm( &comm );
96     }
97
98     MTest_Finalize( err );
99     MPI_Finalize();
100     return 0;
101 }