source: CIVL/examples/contracts/contractsMPI/broadcast_exception.c@ ff25b9a

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

corresponding changes for the new implementation of $mpi_extentof

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

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