1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 static int test(int myid, int numprocs) {
11 // The tags should match on the sender and receiver side.
12 // The distinction between sendtag and recvtag is mainly
13 // useful to make some other Recv or Send calls match the sendrecv.
20 int buffer[BUFLEN], buffer2[BUFLEN];
24 for (i=0;i<BUFLEN;i++) {
28 right = (myid + 1) % numprocs;
33 /* performs a right-to-left shift of vectors */
34 MPI_Sendrecv(buffer, 10, MPI_INT, left, TAG_SND, buffer2, 10, MPI_INT, right, TAG_RCV, MPI_COMM_WORLD, &status);
36 for (i=0;i<BUFLEN;i++) {
37 if (buffer2[i]!=((myid+1)%numprocs)) {
38 fprintf(stderr,"[%d] error: should have values %d, has %d\n",myid,myid-1,buffer[i]);
45 int main(int argc, char *argv[])
50 MPI_Init(&argc,&argv);
51 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
52 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
56 printf("\n *** MPI_Sendrecv test ***\n\n");
58 if ( test(myid,numprocs)) {
59 fprintf(stderr,"[%d] ok.\n",myid);
62 fprintf(stderr,"[%d] failed.\n",myid);