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

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

commit updated tests

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

  • Property mode set to 100644
File size: 851 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 @ waitsfor root;
12 @*/
13int broadcast(int * buf, int count,
14 MPI_Datatype datatype, int root, MPI_Comm comm) {
15 int nprocs, rank;
16 int tag = 999;
17
18 MPI_Comm_size(comm, &nprocs);
19 MPI_Comm_rank(comm, &rank);
20 if (rank == root) {
21 for (int i = 0; i < nprocs; i++)
22 if (i != root)
23 MPI_Send(buf, count, MPI_INT, i, tag, comm);
24 } else
25 MPI_Recv(buf, count, MPI_INT, root, tag, comm,
26 MPI_STATUS_IGNORE);
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.