1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 This program tests MPI_Alltoallv by having processor each process
13 send data to two neighbors only, using counts of 0 for the other processes.
14 This idiom is sometimes used for halo exchange operations.
16 Because there are separate send and receive types to alltoallv,
17 there need to be tests to rearrange data on the fly. Not done yet.
19 Currently, the test uses only MPI_INT; this is adequate for testing systems
20 that use point-to-point operations
23 int main( int argc, char **argv )
29 int *sendcounts, *recvcounts, *rdispls, *sdispls;
31 int left, right, length;
33 MTest_Init( &argc, &argv );
36 while (MTestGetIntracommGeneral( &comm, 2, 1 )) {
37 if (comm == MPI_COMM_NULL) continue;
39 MPI_Comm_size( comm, &size );
40 MPI_Comm_rank( comm, &rank );
42 if (size < 3) continue;
44 /* Create and load the arguments to alltoallv */
45 sendcounts = (int *)malloc( size * sizeof(int) );
46 recvcounts = (int *)malloc( size * sizeof(int) );
47 rdispls = (int *)malloc( size * sizeof(int) );
48 sdispls = (int *)malloc( size * sizeof(int) );
49 if (!sendcounts || !recvcounts || !rdispls || !sdispls) {
50 fprintf( stderr, "Could not allocate arg items!\n" );
55 /* Get the neighbors */
56 left = (rank - 1 + size) % size;
57 right = (rank + 1) % size;
59 /* Set the defaults */
60 for (i=0; i<size; i++) {
67 for (length=1; length < 66000; length = length*2+1 ) {
69 sbuf = (int *)malloc( 2 * length * sizeof(int) );
70 rbuf = (int *)malloc( 2 * length * sizeof(int) );
72 fprintf( stderr, "Could not allocate buffers!\n" );
77 /* Load up the buffers */
78 for (i=0; i<length; i++) {
79 sbuf[i] = i + 100000*rank;
80 sbuf[i+length] = i + 100000*rank;
82 rbuf[i+length] = -i-length;
84 sendcounts[left] = length;
85 sendcounts[right] = length;
86 recvcounts[left] = length;
87 recvcounts[right] = length;
89 rdispls[right] = length;
91 sdispls[right] = length;
93 MPI_Alltoallv( sbuf, sendcounts, sdispls, MPI_INT,
94 rbuf, recvcounts, rdispls, MPI_INT, comm );
99 for (i=0; i<length; i++) {
100 if (p[i] != i + 100000 * left) {
102 fprintf( stderr, "[%d from %d] got %d expected %d for %dth\n",
103 rank, left, p[i], i + 100000 * left, i );
109 p = rbuf + length; /* right */
110 for (i=0; i<length; i++) {
111 if (p[i] != i + 100000 * right) {
113 fprintf( stderr, "[%d from %d] got %d expected %d for %dth\n",
114 rank, right, p[i], i + 100000 * right, i );
128 MTestFreeComm( &comm );
131 MTest_Finalize( err );