| 1 | /* CIVL model of simple hybrid MPI+threads program.
|
|---|
| 2 | * The program has a defect.
|
|---|
| 3 | */
|
|---|
| 4 | #include<comm.cvh>
|
|---|
| 5 | #include<stdio.h>
|
|---|
| 6 | #include "mp_root2.cvh"
|
|---|
| 7 | #define TAG 0
|
|---|
| 8 |
|
|---|
| 9 | void MPI_Process (int __rank) {
|
|---|
| 10 | #include "mp_proc2.cvh"
|
|---|
| 11 | int rank;
|
|---|
| 12 | _Bool tStart = $false;
|
|---|
| 13 | MPI_Comm MPI_COMM_WORLD = $comm_create($here, __MPI_Comm_World, __rank);
|
|---|
| 14 |
|
|---|
| 15 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 16 | $proc threads[2];
|
|---|
| 17 | void Thread(int tid) {
|
|---|
| 18 | int x = 2*rank + tid, y;
|
|---|
| 19 |
|
|---|
| 20 | $when(tStart);
|
|---|
| 21 | for (int j=0; j<2; j++) {
|
|---|
| 22 | if (rank == 1) {
|
|---|
| 23 | for (int i=0; i<2; i++)
|
|---|
| 24 | MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
|
|---|
| 25 | for (int i=0; i<2; i++)
|
|---|
| 26 | MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 27 | } else if (rank == 0) {
|
|---|
| 28 | for (int i=0; i<2; i++)
|
|---|
| 29 | MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 30 | for (int i=0; i<2; i++)
|
|---|
| 31 | MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | for (int i=0; i<2; i++) {
|
|---|
| 36 | threads[i] = $spawn Thread(i);
|
|---|
| 37 | }
|
|---|
| 38 | tStart = $true;
|
|---|
| 39 | for (int i=0; i<2; i++) $wait(threads[i]);
|
|---|
| 40 | $comm_destroy(MPI_COMM_WORLD);
|
|---|
| 41 | }
|
|---|