| 1 | /* CIVL model of simple hybrid MPI+threads program.
|
|---|
| 2 | * The program has a defect.
|
|---|
| 3 | * Commnad line execution:
|
|---|
| 4 | * civl verify -min mpi-pthreads.cvl
|
|---|
| 5 | */
|
|---|
| 6 | #include<civlc.h>
|
|---|
| 7 | #define TAG 0
|
|---|
| 8 |
|
|---|
| 9 | $comm comm;
|
|---|
| 10 | _Bool initialized = $false;
|
|---|
| 11 |
|
|---|
| 12 | void MPI_Process (int pid) {
|
|---|
| 13 | _Bool threadsInit = $false;
|
|---|
| 14 | $proc threads[2];
|
|---|
| 15 |
|
|---|
| 16 | void Thread(int tid) {
|
|---|
| 17 | int x = pid;
|
|---|
| 18 | $message in, out = $message_pack(pid, 1-pid, TAG, &x, sizeof(int));
|
|---|
| 19 |
|
|---|
| 20 | $when(threadsInit) ;
|
|---|
| 21 | for (int j=0; j<2; j++) {
|
|---|
| 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);
|
|---|
| 25 | } else {
|
|---|
| 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);
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | $when (initialized);
|
|---|
| 33 | for (int i=0; i<2; i++) {
|
|---|
| 34 | threads[i] = $spawn Thread(i);
|
|---|
| 35 | $comm_add(&comm, threads[i], pid);
|
|---|
| 36 | }
|
|---|
| 37 | threadsInit = $true;
|
|---|
| 38 | for (int i=0; i<2; i++) $wait(threads[i]);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | void main() {
|
|---|
| 42 | $proc procs[2];
|
|---|
| 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]);
|
|---|
| 48 | }
|
|---|