source: CIVL/examples/contracts/contractsMPI/civl_mpi_collectives/broadcast.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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