4 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];
19 for (i=0;i<BUFLEN;i++) {
23 right = (myid + 1) % numprocs;
28 /* performs a right-to-left shift of vectors */
29 MPI_Sendrecv(buffer, 10, MPI_INT, left, TAG_SND, buffer2, 10, MPI_INT, right, TAG_RCV, MPI_COMM_WORLD, &status);
31 for (i=0;i<BUFLEN;i++) {
32 if (buffer2[i]!=((myid+1)%numprocs)) {
33 fprintf(stderr,"[%d] error: should have values %d, has %d\n",myid,myid-1,buffer[i]);
40 int main(int argc, char *argv[])
45 MPI_Init(&argc,&argv);
46 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
47 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
51 printf("\n *** MPI_Sendrecv test ***\n\n");
53 if ( test(myid,numprocs)) {
54 fprintf(stderr,"[%d] ok.\n",myid);
57 fprintf(stderr,"[%d] failed.\n",myid);