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" );
54 /* Get the neighbors */
55 left = (rank - 1 + size) % size;
56 right = (rank + 1) % size;
58 /* Set the defaults */
59 for (i=0; i<size; i++) {
66 for (length=1; length < 66000; length = length*2+1 ) {
68 sbuf = (int *)malloc( 2 * length * sizeof(int) );
69 rbuf = (int *)malloc( 2 * length * sizeof(int) );
71 fprintf( stderr, "Could not allocate buffers!\n" );
75 /* Load up the buffers */
76 for (i=0; i<length; i++) {
77 sbuf[i] = i + 100000*rank;
78 sbuf[i+length] = i + 100000*rank;
80 rbuf[i+length] = -i-length;
82 sendcounts[left] = length;
83 sendcounts[right] = length;
84 recvcounts[left] = length;
85 recvcounts[right] = length;
87 rdispls[right] = length;
89 sdispls[right] = length;
91 MPI_Alltoallv( sbuf, sendcounts, sdispls, MPI_INT,
92 rbuf, recvcounts, rdispls, MPI_INT, comm );
97 for (i=0; i<length; i++) {
98 if (p[i] != i + 100000 * left) {
100 fprintf( stderr, "[%d from %d] got %d expected %d for %dth\n",
101 rank, left, p[i], i + 100000 * left, i );
107 p = rbuf + length; /* right */
108 for (i=0; i<length; i++) {
109 if (p[i] != i + 100000 * right) {
111 fprintf( stderr, "[%d from %d] got %d expected %d for %dth\n",
112 rank, right, p[i], i + 100000 * right, i );
126 MTestFreeComm( &comm );
129 MTest_Finalize( err );