source: CIVL/examples/mpi/sendrecv.c

main
Last change on this file 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
RevLine 
[447e48c]1#include <mpi.h>
2#include <stdio.h>
3#include <civlc.cvh>
4
5#define FROMRIGHT 0
6#define FROMLEFT 1
7
[024a9eb]8$input int _mpi_nprocs = 3;
[447e48c]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);
[4e72b94]17 left = (rank == 0) ? size - 1 : rank - 1;
18 right = (rank == (size - 1)) ? 0 : rank + 1;
[447e48c]19 MPI_Sendrecv(&rank, 1, MPI_INT, left, FROMRIGHT, &recv, 1, MPI_INT,
20 right, FROMRIGHT, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
[4e72b94]21 $assert(recv == right);
[447e48c]22 MPI_Sendrecv(&rank, 1, MPI_INT, right, FROMLEFT, &recv, 1,
23 MPI_INT, left, FROMLEFT, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
[4e72b94]24 $assert(recv == left);
[447e48c]25 MPI_Finalize();
26 return 0;
27}
Note: See TracBrowser for help on using the repository browser.