Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / sndrcvrpl2.c
1
2 /* 
3  * Based on a program from James Clippinger (james@cs.dartmouth.edu), 
4  * http://www.cs.dartmouth.edu/~james/.
5  *
6  */
7 #include "test.h"
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "mpi.h"
11
12 int main( int argc, char **argv )
13 {
14     MPI_Status status;
15     int count, rank, size,  dest, source, i, err = 0, toterr;
16     long *buf;
17
18     /* Initialize MPI and get my rank and total number of
19        processors */
20     
21     MPI_Init(&argc, &argv);
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     MPI_Comm_size(MPI_COMM_WORLD, &size);
24
25     /* Send-receive-replace the buffer */
26     count  = 1 << 14;
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;
32
33 /*
34     fprintf(stderr, "Proc %d: About to SRR, dest proc %d, source proc 
35 %d\n",
36             rank, dest, source);
37  */
38     MPI_Sendrecv_replace( buf, count, MPI_LONG, dest, 
39                           1, source, 1, MPI_COMM_WORLD, &status );
40
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 );
46         }
47     }
48 /*
49     fprintf(stderr, "Done with SRR on proc %d\n", rank);
50  */
51
52     /* Finalize everything */
53     MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
54     if (rank == 0) {
55         if (toterr == 0) 
56             printf( " No Errors\n" );
57         else
58             printf( "Test failed with %d errors!\n", toterr );
59     }
60     free( buf );
61     
62     MPI_Finalize();
63     return 0;
64 }