source: CIVL/examples/contracts/contractsMPI/broadcast.c@ 9e09ac6

1.23 2.0 main test-branch
Last change on this file since 9e09ac6 was e93c797, checked in by Ziqing Luo <ziqing@…>, 8 years ago

change PARSE_ACSL to CVL_ACSL

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@4569 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#define DATA_LIMIT 1024
7
8/*@
9 @ \mpi_collective(comm, P2P):
10 @ requires 0 <= root && root < \mpi_comm_size;
11 @ requires \mpi_agree(root) && \mpi_agree(count * \mpi_extent(datatype));
12 @ requires 0 < count && count * \mpi_extent(datatype) < DATA_LIMIT;
13 @ requires \mpi_valid(buf, count, datatype);
14 @ ensures \mpi_agree(\mpi_region(buf, count, datatype));
15 @ behavior nonroot:
16 @ assumes \mpi_comm_rank != root;
17 @ assigns \mpi_region(buf, count, datatype);
18 @ waitsfor root;
19 @*/
20int broadcast(void * buf, int count,
21 MPI_Datatype datatype, int root, MPI_Comm comm) {
22 int nprocs, rank;
23 int tag = 999;
24
25 MPI_Comm_size(comm, &nprocs);
26 MPI_Comm_rank(comm, &rank);
27 printf("my rank:%d, root:%d\n", rank, root);
28 if (rank == root) {
29 for (int i = 0; i < nprocs; i++)
30 if (i != root)
31 MPI_Send(buf, count, datatype, i, tag, comm);
32 } else
33 MPI_Recv(buf, count, datatype, root, tag, comm,
34 MPI_STATUS_IGNORE);
35 return 0;
36}
Note: See TracBrowser for help on using the repository browser.