3 * Based on a program from James Clippinger (james@cs.dartmouth.edu),
4 * http://www.cs.dartmouth.edu/~james/.
12 int main( int argc, char **argv )
15 int count, rank, size, dest, source, i, err = 0, toterr;
18 /* Initialize MPI and get my rank and total number of
21 MPI_Init(&argc, &argv);
22 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 /* Send-receive-replace the buffer */
27 buf = (long *)malloc( count * sizeof(long) );
28 for (i=0; i<count; i++)
29 buf[i] = rank + size*i;
30 dest = (rank + 1) % size;
31 source = (rank + size - 1) % size;
34 fprintf(stderr, "Proc %d: About to SRR, dest proc %d, source proc
38 MPI_Sendrecv_replace( buf, count, MPI_LONG, dest,
39 1, source, 1, MPI_COMM_WORLD, &status );
41 for (i=0; i<count; i++) {
42 if (buf[i] != source + size*i) {
43 if (err++ > 10) break;
44 printf( "Received %ld in buf[%d]; expected %d\n",
45 buf[i], i, source + size*i );
49 fprintf(stderr, "Done with SRR on proc %d\n", rank);
52 /* Finalize everything */
53 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
56 printf( " No Errors\n" );
58 printf( "Test failed with %d errors!\n", toterr );