Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icalltoallw.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_Alltoallw by having processor i send different
13   amounts of data to each processor.  This is just the MPI_Alltoallv test,
14   but with displacements in bytes rather than units of the datatype.
15
16   Because there are separate send and receive types to alltoallw,
17   there need to be tests to rearrange data on the fly.  Not done yet.
18   
19   The first test sends i items to processor i from all processors.
20
21   Currently, the test uses only MPI_INT; this is adequate for testing systems
22   that use point-to-point operations
23  */
24
25 int main( int argc, char **argv )
26 {
27
28     MPI_Comm comm;
29     int      *sbuf, *rbuf;
30     int      rank, size, lsize, asize;
31     int      *sendcounts, *recvcounts, *rdispls, *sdispls;
32     int      i, j, *p, err;
33     MPI_Datatype *sendtypes, *recvtypes;
34     int      leftGroup;
35
36     MTest_Init( &argc, &argv );
37     err = 0;
38
39     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
40       if (comm == MPI_COMM_NULL) continue;
41
42       /* Create the buffer */
43       MPI_Comm_size( comm, &lsize );
44       MPI_Comm_remote_size( comm, &size );
45       asize = (lsize > size) ? lsize : size;
46       MPI_Comm_rank( comm, &rank );
47       sbuf = (int *)malloc( size * size * sizeof(int) );
48       rbuf = (int *)malloc( asize * asize * sizeof(int) );
49       if (!sbuf || !rbuf) {
50         fprintf( stderr, "Could not allocated buffers!\n" );
51         MPI_Abort( comm, 1 );
52         exit(1);
53       }
54       
55       /* Load up the buffers */
56       for (i=0; i<size*size; i++) {
57         sbuf[i] = i + 100*rank;
58         rbuf[i] = -i;
59       }
60
61       /* Create and load the arguments to alltoallv */
62       sendcounts = (int *)malloc( size * sizeof(int) );
63       recvcounts = (int *)malloc( size * sizeof(int) );
64       rdispls    = (int *)malloc( size * sizeof(int) );
65       sdispls    = (int *)malloc( size * sizeof(int) );
66       sendtypes  = (MPI_Datatype *)malloc( size * sizeof(MPI_Datatype) );
67       recvtypes  = (MPI_Datatype *)malloc( size * sizeof(MPI_Datatype) );
68       if (!sendcounts || !recvcounts || !rdispls || !sdispls || !sendtypes || !recvtypes) {
69         fprintf( stderr, "Could not allocate arg items!\n" );
70         MPI_Abort( comm, 1 );
71         exit(1);
72       }
73       /* Note that process 0 sends no data (sendcounts[0] = 0) */
74       for (i=0; i<size; i++) {
75         sendcounts[i] = i;
76         sdispls[i]    = (((i+1) * (i))/2) * sizeof(int);
77         sendtypes[i]  = MPI_INT;
78         recvcounts[i] = rank;
79         rdispls[i]    = i * rank * sizeof(int);
80         recvtypes[i]  = MPI_INT;
81       }
82       MPI_Alltoallw( sbuf, sendcounts, sdispls, sendtypes,
83                      rbuf, recvcounts, rdispls, recvtypes, comm );
84       
85       /* Check rbuf */
86       for (i=0; i<size; i++) {
87         p = rbuf + rdispls[i]/sizeof(int);
88         for (j=0; j<rank; j++) {
89           if (p[j] != i * 100 + (rank*(rank+1))/2 + j) {
90             fprintf( stderr, "[%d] got %d expected %d for %dth\n",
91                      rank, p[j],(i*(i+1))/2 + j, j );
92             err++;
93           }
94         }
95       }
96
97       free(sendtypes);
98       free(recvtypes);
99       free( sdispls );
100       free( rdispls );
101       free( recvcounts );
102       free( sendcounts );
103       free( rbuf );
104       free( sbuf );
105       MTestFreeComm( &comm );
106     }
107
108     MTest_Finalize( err );
109     MPI_Finalize();
110     return 0;
111 }