1 /* Copyright (c) 2009-2010, 2012. 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)
12 // The tags should match on the sender and receiver side.
13 // The distinction between sendtag and recvtag is mainly
14 // useful to make some other Recv or Send calls match the sendrecv.
21 int buffer[BUFLEN], buffer2[BUFLEN];
25 for (i = 0; i < BUFLEN; i++) {
29 right = (myid + 1) % numprocs;
34 /* performs a right-to-left shift of vectors */
35 MPI_Sendrecv(buffer, 10, MPI_INT, left, TAG_SND, buffer2, 10, MPI_INT,
36 right, TAG_RCV, MPI_COMM_WORLD, &status);
38 for (i = 0; i < BUFLEN; i++) {
39 if (buffer2[i] != right) {
40 fprintf(stderr, "[%d] error: should have values %d, has %d\n", myid,
48 int main(int argc, char *argv[])
53 MPI_Init(&argc, &argv);
54 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
55 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
59 printf("\n *** MPI_Sendrecv test ***\n\n");
61 if (test(myid, numprocs)) {
62 fprintf(stderr, "[%d] ok.\n", myid);
64 fprintf(stderr, "[%d] failed.\n", myid);