source: CIVL/examples/concurrency/hybrid_new.cvl

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: 1004 bytes
Line 
1#include<civlc.cvh>
2#include <mpi.h>
3#include <stdio.h>
4#define TAG 0
5
6int main(int argc, char* argv[]) {
7 int size, rank;
8 _Bool tStart = $false;
9 $proc threads[2];
10
11 MPI_Init(&argc, &argv);
12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13 MPI_Comm_size(MPI_COMM_WORLD, &size);
14
15 void Thread(int tid) {
16 int x = 2*rank + tid, y;
17
18 $when(tStart);
19 for (int j=0; j<2; j++) {
20 if (rank == 1) {
21 for (int i=0; i<2; i++)
22 MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
23 for (int i=0; i<2; i++)
24 MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
25 } else {
26 for (int i=0; i<2; i++)
27 MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
28 for (int i=0; i<2; i++)
29 MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
30 }
31 }
32 }
33 for(int i=0; i<2; i++)
34 threads[i] = $spawn Thread(i);
35 tStart = $true;
36 for (int i=0; i<2; i++) $wait(threads[i]);
37 MPI_Finalize();
38 return 0;
39}
Note: See TracBrowser for help on using the repository browser.