4 static int test(int myid, int numprocs) {
5 // The tags should match on the sender and receiver side.
6 // The distinction between sendtag and recvtag is mainly
7 // useful to make some other Recv or Send calls match the sendrecv.
14 int buffer[BUFLEN], buffer2[BUFLEN];
18 for (i=0;i<BUFLEN;i++) {
22 right = (myid + 1) % numprocs;
27 /* performs a right-to-left shift of vectors */
28 MPI_Sendrecv(buffer, 10, MPI_INT, left, TAG_SND, buffer2, 10, MPI_INT, right, TAG_RCV, MPI_COMM_WORLD, &status);
30 for (i=0;i<BUFLEN;i++) {
31 if (buffer2[i]!=((myid+1)%numprocs)) {
32 fprintf(stderr,"[%d] error: should have values %d, has %d\n",myid,myid-1,buffer[i]);
39 int main(int argc, char *argv[])
44 MPI_Init(&argc,&argv);
45 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
46 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
50 printf("\n *** MPI_Sendrecv test ***\n\n");
52 if ( test(myid,numprocs)) {
53 fprintf(stderr,"[%d] ok.\n",myid);
56 fprintf(stderr,"[%d] failed.\n",myid);