source: CIVL/examples/messagePassing/mpi-pthreads.cvl@ cf2a996

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

cleaned up examples and tests.

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

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