1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include<mpi.h>
|
|---|
| 2 | #include<civlc.cvh>
|
|---|
| 3 |
|
|---|
| 4 | /*@
|
|---|
| 5 | @ requires \valid(buf + (0 .. count));
|
|---|
| 6 | @ \mpi_collective(comm, P2P):
|
|---|
| 7 | @ requires 0 <= root && root < \mpi_comm_size;
|
|---|
| 8 | @ requires \mpi_agree(root) && \mpi_agree(count);
|
|---|
| 9 | @ requires 0 < count && count < 10;
|
|---|
| 10 | @ ensures \mpi_equals(buf, count, MPI_INT, \remote(buf, root));
|
|---|
| 11 | @*/
|
|---|
| 12 | int broadcast(int * buf, int count,
|
|---|
| 13 | MPI_Datatype datatype, int root, MPI_Comm comm) {
|
|---|
| 14 | int nprocs, rank;
|
|---|
| 15 | int tag = 999;
|
|---|
| 16 |
|
|---|
| 17 | MPI_Comm_size(comm, &nprocs);
|
|---|
| 18 | MPI_Comm_rank(comm, &rank);
|
|---|
| 19 | if (rank == root) {
|
|---|
| 20 | for (int i = 0; i < nprocs; i++)
|
|---|
| 21 | if (i != root)
|
|---|
| 22 | MPI_Send(buf, count, MPI_INT, i, tag, comm);
|
|---|
| 23 | } else
|
|---|
| 24 | MPI_Recv(buf, count, MPI_INT, root, tag, comm,
|
|---|
| 25 | MPI_STATUS_IGNORE);
|
|---|
| 26 | buf[0] = rank;
|
|---|
| 27 | return 0;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | int main() {
|
|---|
| 32 | broadcast(NULL, 0, MPI_INT, 0, (MPI_Comm)0);
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.