main
test-branch
| Line | |
|---|
| 1 | /* cycle: Each process send its rank to its right neighbor and
|
|---|
| 2 | receives message from the left neighbor.
|
|---|
| 3 | */
|
|---|
| 4 | #include<mpi.h>
|
|---|
| 5 | #include<civl-mpi.cvh>
|
|---|
| 6 |
|
|---|
| 7 | int main(int argc, char * argv[]) {
|
|---|
| 8 | int x, rank, nprocs;
|
|---|
| 9 | int left, right;
|
|---|
| 10 | MPI_Comm comm = MPI_COMM_WORLD;
|
|---|
| 11 |
|
|---|
| 12 | MPI_Init(&argc, &argv);
|
|---|
| 13 | MPI_Comm_rank(comm, &rank);
|
|---|
| 14 | MPI_Comm_size(comm, &nprocs);
|
|---|
| 15 | left = (rank + 1)%nprocs;
|
|---|
| 16 | right = (rank - 1)%nprocs;
|
|---|
| 17 | for(int i = 0; i < nprocs; i++) {
|
|---|
| 18 | MPI_Sendrecv(&rank, 1, MPI_INT, right, 0,
|
|---|
| 19 | &x, 1, MPI_INT, left, 0, comm,
|
|---|
| 20 | MPI_STATUS_IGNORE);
|
|---|
| 21 | $mpi_coassert(comm, rank == x@right);
|
|---|
| 22 | }
|
|---|
| 23 | MPI_Finalize();
|
|---|
| 24 | return 0;
|
|---|
| 25 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.