1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | #include <pthread.h>
|
|---|
| 2 | #include <mpi.h>
|
|---|
| 3 |
|
|---|
| 4 | #define TAG 99
|
|---|
| 5 |
|
|---|
| 6 | $input int _NPROCS = 2;
|
|---|
| 7 |
|
|---|
| 8 | void * Thread(void * tid) {
|
|---|
| 9 | int rank, x, y;
|
|---|
| 10 |
|
|---|
| 11 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 12 | x = 2*rank + (int)tid;
|
|---|
| 13 | for (int j=0; j<2; j++) {
|
|---|
| 14 | if (rank == 0) {
|
|---|
| 15 | for (int i=0; i<2; i++)
|
|---|
| 16 | MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
|
|---|
| 17 | for (int i=0; i<2; i++)
|
|---|
| 18 | MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 19 | } else if (rank == 1) {
|
|---|
| 20 | for (int i=0; i<2; i++)
|
|---|
| 21 | MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 22 | for (int i=0; i<2; i++)
|
|---|
| 23 | MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
|
|---|
| 24 | }
|
|---|
| 25 | }
|
|---|
| 26 | pthread_exit(NULL);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | int main(int argc, char * argv[]) {
|
|---|
| 30 | pthread_t threads[2];
|
|---|
| 31 |
|
|---|
| 32 | MPI_Init(&argc, &argv);
|
|---|
| 33 | for (int i=0; i<2; i++) {
|
|---|
| 34 | pthread_create(&threads[i], NULL, Thread, (void *)(long)i);
|
|---|
| 35 | }
|
|---|
| 36 | for (int i=0; i<2; i++) {
|
|---|
| 37 | pthread_join(threads[i], NULL);
|
|---|
| 38 | }
|
|---|
| 39 | MPI_Finalize();
|
|---|
| 40 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.