source: CIVL/examples/mpi/mpiFeature/simple_nb_good.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: 1.1 KB
RevLine 
[056aaa8]1/******************************************************************************
2* FILE: mpi_ringtopo.c
3* DESCRIPTION:
4* MPI tutorial example code: Non-Blocking Send/Receive
5* AUTHOR: Blaise Barney
6* LAST REVISED: 04/02/05
7******************************************************************************/
8#include "mpi.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12int main (int argc, char *argv[])
13{
14int numtasks, rank, next, prev, buf[2], tag1=1, tag2=2;
15MPI_Request reqs[4];
16MPI_Status stats[4];
17
18MPI_Init(&argc,&argv);
19MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
20MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21
22prev = rank-1;
23next = rank+1;
24if (rank == 0) prev = numtasks - 1;
25if (rank == (numtasks - 1)) next = 0;
26
27MPI_Irecv(&buf[0], 1, MPI_INT, prev, tag1, MPI_COMM_WORLD, &reqs[0]);
28MPI_Irecv(&buf[1], 1, MPI_INT, next, tag2, MPI_COMM_WORLD, &reqs[1]);
29
30MPI_Isend(&rank, 1, MPI_INT, prev, tag2, MPI_COMM_WORLD, &reqs[2]);
31MPI_Isend(&rank, 1, MPI_INT, next, tag1, MPI_COMM_WORLD, &reqs[3]);
32
33MPI_Waitall(4, reqs, stats);
34printf("Task %d communicated with tasks %d & %d\n",rank,prev,next);
35
36MPI_Finalize();
37}
38
Note: See TracBrowser for help on using the repository browser.