source: CIVL/examples/messagePassing/hybrid.cvl@ c46e702

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

implemented MPI+Threads. Now hybrid.cvl with -min, -por=new terminates in a few seconds. But hybrid2.cvl still seems to run forever, need to look into it further.

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

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[28717d7]1/* CIVL model of simple hybrid MPI+threads program.
2 * The program has a defect.
3 */
4#include<civlc.h>
5#define TAG 0
6
[b70deeb]7$comm comm;
8_Bool initialized = $false;
9
10void MPI_Process (int pid) {
[c46e702]11 _Bool threadsInit = $false;
[28717d7]12 $proc threads[2];
[c46e702]13
[28717d7]14 void Thread(int tid) {
[b70deeb]15 int x = pid;
16 $message in, out = $message_pack(pid, 1-pid, TAG, &x, sizeof(int));
[28717d7]17
[c46e702]18 $when(threadsInit) ;
[28717d7]19 for (int j=0; j<2; j++) {
[b70deeb]20 if (pid == 1) {
21 for (int i=0; i<2; i++) $comm_enqueue(&comm, out);
22 for (int i=0; i<2; i++) in = $comm_dequeue(&comm, 1-pid, pid, TAG);
[28717d7]23 } else {
[b70deeb]24 for (int i=0; i<2; i++) in = $comm_dequeue(&comm, 1-pid, pid, TAG);
25 for (int i=0; i<2; i++) $comm_enqueue(&comm, out);
[28717d7]26 }
27 }
28 }
[b70deeb]29
[c46e702]30 $when (initialized);
31 for (int i=0; i<2; i++) {
32 threads[i] = $spawn Thread(i);
33 $comm_add(&comm, threads[i]);
[28717d7]34 }
[c46e702]35 threadsInit = $true;
36 for (int i=0; i<2; i++) $wait threads[i];
[28717d7]37}
[b70deeb]38
39void main() {
40 $proc procs[2];
[c46e702]41
42 for (int i=0; i<2; i++) procs[i] = $spawn MPI_Process(i);
43 comm = $comm_create(2, procs);
44 initialized = $true;
45 for (int i=0; i<2; i++) $wait procs[i];
[b70deeb]46}
Note: See TracBrowser for help on using the repository browser.