main
test-branch
| Line | |
|---|
| 1 | #include<mpi.h>
|
|---|
| 2 | #include<assert.h>
|
|---|
| 3 |
|
|---|
| 4 | int nprocs;
|
|---|
| 5 | int myrank;
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | void main() {
|
|---|
| 9 | int argc;
|
|---|
| 10 | char **argv;
|
|---|
| 11 | double buf[3];
|
|---|
| 12 | MPI_Status status;
|
|---|
| 13 | int count;
|
|---|
| 14 |
|
|---|
| 15 | MPI_Init(&argc, &argv);
|
|---|
| 16 | MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
|
|---|
| 17 | if(myrank == 0) {
|
|---|
| 18 | buf[0] = 1.0;
|
|---|
| 19 | buf[1] = 1.1;
|
|---|
| 20 | MPI_Send(&buf[0], 2, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
|
|---|
| 21 | } else {
|
|---|
| 22 | buf[0] = 0.0;
|
|---|
| 23 | buf[1] = 0.0;
|
|---|
| 24 | buf[2] = 0.0;
|
|---|
| 25 | MPI_Recv(&buf[0], 3, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
|
|---|
| 26 | MPI_Get_count(&status, MPI_DOUBLE, &count);
|
|---|
| 27 | assert(count == 2);
|
|---|
| 28 | assert(buf[0] == 1.0 && buf[1] == 1.1 && buf[2] == 0.0);
|
|---|
| 29 | }
|
|---|
| 30 | MPI_Finalize();
|
|---|
| 31 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.