1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include<civlc.cvh>
|
|---|
| 2 | #include <mpi.h>
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 | #define TAG 0
|
|---|
| 5 |
|
|---|
| 6 | int main(int argc, char* argv[]) {
|
|---|
| 7 | int size, rank;
|
|---|
| 8 | _Bool tStart = $false;
|
|---|
| 9 | $proc threads[2];
|
|---|
| 10 |
|
|---|
| 11 | MPI_Init(&argc, &argv);
|
|---|
| 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 13 | MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|---|
| 14 |
|
|---|
| 15 | void Thread(int tid) {
|
|---|
| 16 | int x = 2*rank + tid, y;
|
|---|
| 17 |
|
|---|
| 18 | $when(tStart);
|
|---|
| 19 | for (int j=0; j<2; j++) {
|
|---|
| 20 | if (rank == 1) {
|
|---|
| 21 | for (int i=0; i<2; i++)
|
|---|
| 22 | MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
|
|---|
| 23 | for (int i=0; i<2; i++)
|
|---|
| 24 | MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 25 | } else {
|
|---|
| 26 | for (int i=0; i<2; i++)
|
|---|
| 27 | MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 28 | for (int i=0; i<2; i++)
|
|---|
| 29 | MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | for(int i=0; i<2; i++)
|
|---|
| 34 | threads[i] = $spawn Thread(i);
|
|---|
| 35 | tStart = $true;
|
|---|
| 36 | for (int i=0; i<2; i++) $wait(threads[i]);
|
|---|
| 37 | MPI_Finalize();
|
|---|
| 38 | return 0;
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.