main
test-branch
| Rev | Line | |
|---|
| [5d951df] | 1 | /* This example show how to collectively call MPI collective
|
|---|
| 2 | functions. They must be called by every included process in a same
|
|---|
| 3 | order. */
|
|---|
| [ec2d23f2] | 4 | #include <mpi.h>
|
|---|
| 5 | #include <assert.h>
|
|---|
| 6 |
|
|---|
| 7 | int main(int argc, char * argv[]) {
|
|---|
| 8 | int nprocs, rank;
|
|---|
| 9 | int num;
|
|---|
| 10 | int recv;
|
|---|
| 11 |
|
|---|
| 12 | MPI_Init(&argc, &argv);
|
|---|
| 13 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 14 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 15 | if(rank == 0) num = 3;
|
|---|
| 16 | MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 17 | MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 18 | if(rank == 0) num = recv;
|
|---|
| 19 | MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 20 | assert(num == 3 * nprocs);
|
|---|
| 21 | MPI_Finalize();
|
|---|
| 22 | return 0;
|
|---|
| 23 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.