| 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<comm.cvh>
|
|---|
| 7 | #define TAG 0
|
|---|
| 8 | #define NPROCS 2
|
|---|
| 9 | #define NTHREADS 2
|
|---|
| 10 |
|
|---|
| 11 | $gcomm gcomm = $gcomm_create($here, NPROCS);
|
|---|
| 12 |
|
|---|
| 13 | void MPI_Process (int rank) {
|
|---|
| 14 | $comm comm = $comm_create($here, gcomm, rank);
|
|---|
| 15 | $proc threads[NTHREADS];
|
|---|
| 16 |
|
|---|
| 17 | void Thread(int tid) {
|
|---|
| 18 | int x = rank;
|
|---|
| 19 | $message in, out = $message_pack(rank, 1-rank, TAG, &x, sizeof(int));
|
|---|
| 20 |
|
|---|
| 21 | for (int j=0; j<2; j++) {
|
|---|
| 22 | if (rank == 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-rank, TAG);
|
|---|
| 25 | } else {
|
|---|
| 26 | for (int i=0; i<2; i++) in = $comm_dequeue(comm, 1-rank, TAG);
|
|---|
| 27 | for (int i=0; i<2; i++) $comm_enqueue(comm, out);
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | for (int i=0; i<NTHREADS; i++) threads[i] = $spawn Thread(i);
|
|---|
| 33 | //for (int i=0; i<NTHREADS; i++) $wait(threads[i]);
|
|---|
| 34 | $waitall(threads, NTHREADS);
|
|---|
| 35 | $comm_destroy(comm);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | void main() {
|
|---|
| 39 | $proc procs[NPROCS];
|
|---|
| 40 |
|
|---|
| 41 | for (int i=0; i<NPROCS; i++) procs[i] = $spawn MPI_Process(i);
|
|---|
| 42 | //for (int i=0; i<NPROCS; i++) $wait(procs[i]);
|
|---|
| 43 | $waitall(procs, NPROCS);
|
|---|
| 44 | $gcomm_destroy(gcomm, NULL);
|
|---|
| 45 | }
|
|---|