source: CIVL/examples/mpi/sendrecv.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 759 bytes
Line 
1#include <mpi.h>
2#include <stdio.h>
3#include <civlc.cvh>
4
5#define FROMRIGHT 0
6#define FROMLEFT 1
7
8$input int _mpi_nprocs = 3;
9int main(int argc, char * argv[]) {
10 int rank, size;
11 int recv;
12 int left, right;
13
14 MPI_Init(&argc, &argv);
15 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
16 MPI_Comm_size(MPI_COMM_WORLD, &size);
17 left = (rank == 0) ? size - 1 : rank - 1;
18 right = (rank == (size - 1)) ? 0 : rank + 1;
19 MPI_Sendrecv(&rank, 1, MPI_INT, left, FROMRIGHT, &recv, 1, MPI_INT,
20 right, FROMRIGHT, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
21 $assert(recv == right);
22 MPI_Sendrecv(&rank, 1, MPI_INT, right, FROMLEFT, &recv, 1,
23 MPI_INT, left, FROMLEFT, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
24 $assert(recv == left);
25 MPI_Finalize();
26 return 0;
27}
Note: See TracBrowser for help on using the repository browser.