main
test-branch
| Line | |
|---|
| 1 | /* Reduce_coassert: All processes in the MPI_COMM_WORLD sum up their
|
|---|
| 2 | ranks, the result is reduced to a root process. */
|
|---|
| 3 | #include <mpi.h>
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include <civl-mpi.cvh>
|
|---|
| 6 |
|
|---|
| 7 | int size, rank;
|
|---|
| 8 | int root = 0, sum;
|
|---|
| 9 |
|
|---|
| 10 | int main(int argc, char * argv[]) {
|
|---|
| 11 | MPI_Init(&argc, &argv);
|
|---|
| 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 13 | MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|---|
| 14 | for(int i = 0; i < 4; i++) {
|
|---|
| 15 | MPI_Reduce(&i, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
|
|---|
| 16 | if(!rank)printf("iteration: %d sum=%d\n", i, sum);
|
|---|
| 17 | $mpi_coassert(MPI_COMM_WORLD, sum@root == (i*size));
|
|---|
| 18 | }
|
|---|
| 19 | MPI_Finalize();
|
|---|
| 20 | return 0;
|
|---|
| 21 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.