main
test-branch
| Line | |
|---|
| 1 | /* Good broadcasts.
|
|---|
| 2 | */
|
|---|
| 3 | #include<mpi.h>
|
|---|
| 4 | #include<assert.h>
|
|---|
| 5 |
|
|---|
| 6 | int nprocs;
|
|---|
| 7 | int myrank;
|
|---|
| 8 |
|
|---|
| 9 | #define count 10
|
|---|
| 10 |
|
|---|
| 11 | void main() {
|
|---|
| 12 | int argc;
|
|---|
| 13 | char **argv;
|
|---|
| 14 | double x[count];
|
|---|
| 15 | double y[count];
|
|---|
| 16 | int i;
|
|---|
| 17 |
|
|---|
| 18 | MPI_Init(&argc, &argv);
|
|---|
| 19 | MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
|
|---|
| 20 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 21 | for (i=0; i<count; i++)
|
|---|
| 22 | x[i]=myrank;
|
|---|
| 23 | MPI_Allreduce(&x[0], &y[0], count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
|---|
| 24 | for (i=0; i<count; i++)
|
|---|
| 25 | assert(x[i]==myrank);
|
|---|
| 26 | for (i=0; i<count; i++)
|
|---|
| 27 | assert(y[i]==nprocs*(nprocs-1)/2);
|
|---|
| 28 | MPI_Finalize();
|
|---|
| 29 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.