| [056aaa8] | 1 | /* Minimal example of a mismatch in collective calls.
|
|---|
| 2 | * One proc tries to broadcast then reduce, the others
|
|---|
| 3 | * reduce then broadcast. Call with nprocs=3 or higher.
|
|---|
| 4 | */
|
|---|
| 5 | #include <mpi.h>
|
|---|
| 6 | #include <stdlib.h>
|
|---|
| 7 | #define comm MPI_COMM_WORLD
|
|---|
| 8 |
|
|---|
| 9 | int main(int argc, char * argv[]) {
|
|---|
| 10 | int rank;
|
|---|
| 11 |
|
|---|
| 12 | MPI_Init(&argc, &argv);
|
|---|
| 13 | MPI_Comm_rank(comm, &rank);
|
|---|
| 14 | if (rank == 0) {
|
|---|
| 15 | MPI_Reduce(NULL, NULL, 0, MPI_INT, MPI_SUM, 0, comm);
|
|---|
| 16 | MPI_Bcast(NULL, 0, MPI_INT, 0, comm);
|
|---|
| 17 | }
|
|---|
| 18 | else if (rank == 1) {
|
|---|
| 19 | MPI_Bcast(NULL, 0, MPI_INT, 0, comm);
|
|---|
| 20 | MPI_Reduce(NULL, NULL, 0, MPI_INT, MPI_SUM, 0, comm);
|
|---|
| 21 | } else {
|
|---|
| 22 | MPI_Bcast(NULL, 0, MPI_INT, 1, comm);
|
|---|
| 23 | MPI_Reduce(NULL, NULL, 0, MPI_INT, MPI_SUM, 0, comm);
|
|---|
| 24 | }
|
|---|
| 25 | MPI_Finalize();
|
|---|
| 26 | }
|
|---|