7 This program tests MPI_Alltoallv by having processor i send different
8 amounts of data to each processor.
10 Because there are separate send and receive types to alltoallv,
11 there need to be tests to rearrange data on the fly. Not done yet.
13 The first test sends i items to processor i from all processors.
15 Currently, the test uses only MPI_INT; this is adequate for testing systems
16 that use point-to-point operations
19 int main( int argc, char **argv )
25 int *sendcounts, *recvcounts, *rdispls, *sdispls;
26 int i, j, *p, err, toterr;
28 MPI_Init( &argc, &argv );
31 comm = MPI_COMM_WORLD;
33 /* Create the buffer */
34 MPI_Comm_size( comm, &size );
35 MPI_Comm_rank( comm, &rank );
36 sbuf = (int *)malloc( size * size * sizeof(int) );
37 rbuf = (int *)malloc( size * size * sizeof(int) );
39 fprintf( stderr, "Could not allocated buffers!\n" );
43 /* Load up the buffers */
44 for (i=0; i<size*size; i++) {
45 sbuf[i] = i + 100*rank;
49 /* Create and load the arguments to alltoallv */
50 sendcounts = (int *)malloc( size * sizeof(int) );
51 recvcounts = (int *)malloc( size * sizeof(int) );
52 rdispls = (int *)malloc( size * sizeof(int) );
53 sdispls = (int *)malloc( size * sizeof(int) );
54 if (!sendcounts || !recvcounts || !rdispls || !sdispls) {
55 fprintf( stderr, "Could not allocate arg items!\n" );
58 for (i=0; i<size; i++) {
61 rdispls[i] = i * rank;
62 sdispls[i] = (i * (i+1))/2;
64 MPI_Alltoallv( sbuf, sendcounts, sdispls, MPI_INT,
65 rbuf, recvcounts, rdispls, MPI_INT, comm );
68 for (i=0; i<size; i++) {
69 p = rbuf + rdispls[i];
70 for (j=0; j<rank; j++) {
71 if (p[j] != i * 100 + (rank*(rank+1))/2 + j) {
72 fprintf( stderr, "[%d] got %d expected %d for %dth\n",
73 rank, p[j],(i*(i+1))/2 + j, j );
86 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
87 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
90 fprintf( stderr, "Test FAILED with %d errors\n", toterr );
92 fprintf( stderr, " No Errors\n" );