source: CIVL/examples/concurrency/hybrid_new.cvl@ 0fdf4bd

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 0fdf4bd was 0175332, checked in by Ziqing Luo <ziqing@…>, 11 years ago

rewriten hybrid example

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

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