source: CIVL/examples/contracts/contractsMPI/broadcast.c@ 3c8cc6c

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 3c8cc6c was 1b69190, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Merged from the contract branch. A contract transformer was added.

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

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