source: CIVL/examples/contracts/contractsMPI/broadcast_order.c@ f8f3bec

1.23 2.0 main test-branch
Last change on this file since f8f3bec was c7fc5a5, checked in by Ziqing Luo <ziqing@…>, 10 years ago

add a new test

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@3565 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 807 bytes
Line 
1#include<mpi.h>
2#include<civlc.cvh>
3
4/*@
5 @ \mpi_collective(comm, P2P):
6 @ requires \mpi_valid(buf, count, datatype);
7 @ requires 0 <= root && root < \mpi_comm_size;
8 @ requires \mpi_agree(root) && \mpi_agree(count * \mpi_extent(datatype));
9 @ requires 0 < count && count < 10;
10 @ ensures \mpi_equals(buf, count, datatype, \on(root, buf));
11 @ waitsfor root;
12 @*/
13int broadcast(void * buf, int count,
14 MPI_Datatype datatype, int root, MPI_Comm comm) {
15 int nprocs, rank;
16 int tag = 999;
17
18 MPI_Comm_size(comm, &nprocs);
19 MPI_Comm_rank(comm, &rank);
20 if (rank == root) {
21 for (int i = 0; i < nprocs; i++)
22 if (i != root)
23 MPI_Send(buf, count, datatype, i, tag, comm);
24 } else
25 MPI_Recv(buf, count, datatype, root, tag, comm,
26 MPI_STATUS_IGNORE);
27 return 0;
28}
Note: See TracBrowser for help on using the repository browser.