source: CIVL/examples/MPI/ring1.c@ f6ce0eb

1.23 2.0 main test-branch
Last change on this file since f6ce0eb was 7e53a41, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

fixed the bug in parsing a main function with a non-void return type; fixed a trivial bug in the MPI transformer.

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

  • Property mode set to 100644
File size: 740 bytes
Line 
1#include<mpi.h>
2#include<stdio.h>
3int myrank;
4int nprocs;
5int left;
6int right;
7
8void main(int argc, char **argv) {
9 int i;
10 int data = 0;
11
12 MPI_Init(&argc, &argv);
13 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
14 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
15 left = (myrank+nprocs-1)%nprocs;
16 right = (myrank+nprocs+1)%nprocs;
17 i=0;
18 if (myrank%2==0) {
19 MPI_Send(&data, 0, MPI_INT, right, 0, MPI_COMM_WORLD);
20 MPI_Recv(&data, 0, MPI_INT, left, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
21 } else {
22 MPI_Recv(&data, 0, MPI_INT, left, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
23 MPI_Send(&data, 0, MPI_INT, right, 0, MPI_COMM_WORLD);
24 }
25 printf("I'm process %d.\n", myrank);
26 MPI_Finalize();
27}
Note: See TracBrowser for help on using the repository browser.