1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * This program is written according to the example described in
|
|---|
| 3 | * http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-1.1/node86.htm#Node86
|
|---|
| 4 | */
|
|---|
| 5 | #include<stdio.h>
|
|---|
| 6 | #include<mpi.h>
|
|---|
| 7 | #include<assert.h>
|
|---|
| 8 |
|
|---|
| 9 | int main(int argc, char* argv[]){
|
|---|
| 10 | int rank;
|
|---|
| 11 | int procs;
|
|---|
| 12 | int* sendBuf;
|
|---|
| 13 | int* rcvBuf;
|
|---|
| 14 | int* sum;
|
|---|
| 15 | int buf1, buf2;
|
|---|
| 16 |
|
|---|
| 17 | MPI_Init(&argc,&argv);
|
|---|
| 18 | MPI_Comm_size(MPI_COMM_WORLD, &procs);
|
|---|
| 19 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 20 |
|
|---|
| 21 | if(procs != 2){
|
|---|
| 22 | printf("This program requires exactly two processes.\n");
|
|---|
| 23 | return 1;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | if(rank == 0){
|
|---|
| 27 | buf1=1;
|
|---|
| 28 | buf2=2;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | switch(rank) {
|
|---|
| 32 | case 0:
|
|---|
| 33 | MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 34 | MPI_Send(&buf2, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
|
|---|
| 35 | break;
|
|---|
| 36 | case 1:
|
|---|
| 37 | MPI_Recv(&buf2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|---|
| 38 | MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 39 | break;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | printf("process %d: buf1=%d, buf2=%d\n", rank, buf1, buf2);
|
|---|
| 43 | assert(buf1==1 && buf2 == 2);
|
|---|
| 44 |
|
|---|
| 45 | MPI_Finalize();
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.