| 1 | /* A bad example shows how CIVL catches the misusage of MPI collective
|
|---|
| 2 | routines. In this example, even processes and odd processes calls
|
|---|
| 3 | different MPI collective routines. */
|
|---|
| 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 |
|
|---|
| 18 | if(rank%2 == 0)
|
|---|
| 19 | MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 20 | else
|
|---|
| 21 | MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 22 | if(rank == 0) num = recv;
|
|---|
| 23 | if(rank%2 == 0)
|
|---|
| 24 | MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 25 | else
|
|---|
| 26 | MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 27 | assert(num == 3 * nprocs);
|
|---|
| 28 | MPI_Finalize();
|
|---|
| 29 | return 0;
|
|---|
| 30 | }
|
|---|