1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <comm.cvh>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <civlmpi.cvh>
|
|---|
| 4 | #include <mpi.h>
|
|---|
| 5 |
|
|---|
| 6 | $input int NPROCS = 3;
|
|---|
| 7 | CMPI_Gcomm __MPI_COMM_WORLD;
|
|---|
| 8 | void MPI_Process(int place){
|
|---|
| 9 |
|
|---|
| 10 | MPI_Comm MPI_COMM_WORLD = CMPI_Comm_create($here, __MPI_COMM_WORLD, place);
|
|---|
| 11 | int nprocs, rank, msg;
|
|---|
| 12 | MPI_Status status;
|
|---|
| 13 |
|
|---|
| 14 | __MPI_Init(&MPI_COMM_WORLD);
|
|---|
| 15 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 16 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 17 | if(rank != 0){
|
|---|
| 18 | msg = rank;
|
|---|
| 19 | MPI_Send(&msg, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
|
|---|
| 20 | }
|
|---|
| 21 | else{
|
|---|
| 22 | int source;
|
|---|
| 23 |
|
|---|
| 24 | msg = -1;
|
|---|
| 25 | printf("I'm process %d :\n", rank);
|
|---|
| 26 | MPI_Recv(&msg, 1, MPI_INT, $COMM_ANY_SOURCE, 1, MPI_COMM_WORLD, &status);
|
|---|
| 27 | MPI_Recv(&msg, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &status);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | CMPI_Comm_destroy(MPI_COMM_WORLD);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | void main(){
|
|---|
| 34 |
|
|---|
| 35 | $proc procs[NPROCS];
|
|---|
| 36 |
|
|---|
| 37 | __MPI_COMM_WORLD = CMPI_Gcomm_create($root, NPROCS);
|
|---|
| 38 | for(int i=0; i<NPROCS; i++)
|
|---|
| 39 | procs[i] = $spawn MPI_Process(i);
|
|---|
| 40 | for(int i=0; i<NPROCS; i++)
|
|---|
| 41 | $wait(procs[i]);
|
|---|
| 42 |
|
|---|
| 43 | CMPI_Gcomm_destroy(__MPI_COMM_WORLD);
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.