source: CIVL/examples/experimental/sequential/broadcast_bad.c@ fffb3b88

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

commit work for contracts system

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

  • Property mode set to 100644
File size: 847 bytes
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 @*/
12int 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
31int 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.