1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <stdio.h>
|
|---|
| 2 | #include <mpi.h>
|
|---|
| 3 |
|
|---|
| 4 | $input int _mpi_nprocs = 3;
|
|---|
| 5 |
|
|---|
| 6 | void main(int argc, char * argv[]){
|
|---|
| 7 | int nprocs, rank, msg;
|
|---|
| 8 | MPI_Status status;
|
|---|
| 9 |
|
|---|
| 10 | MPI_Init(&argc, &argv);
|
|---|
| 11 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 12 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 13 | if(rank != 0){
|
|---|
| 14 | msg = rank;
|
|---|
| 15 | MPI_Send(&msg, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
|
|---|
| 16 | }
|
|---|
| 17 | else{
|
|---|
| 18 | int source;
|
|---|
| 19 |
|
|---|
| 20 | msg = -1;
|
|---|
| 21 | printf("I'm process %d :\n", rank);
|
|---|
| 22 | MPI_Recv(&msg, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);
|
|---|
| 23 | MPI_Recv(&msg, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &status);
|
|---|
| 24 | }
|
|---|
| 25 | MPI_Finalize();
|
|---|
| 26 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.