source: CIVL/examples/contracts/contractsMPI/broadcast.c@ f17d4c8

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since f17d4c8 was e93c797, checked in by Ziqing Luo <ziqing@…>, 9 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
RevLine 
[9074a6e]1#include<mpi.h>
2#include<civlc.cvh>
[1b7d18d]3#include<stdio.h>
[e93c797]4#pragma CIVL ACSL
[1b7d18d]5
6#define DATA_LIMIT 1024
7
[9074a6e]8/*@
9 @ \mpi_collective(comm, P2P):
10 @ requires 0 <= root && root < \mpi_comm_size;
[5b6be95]11 @ requires \mpi_agree(root) && \mpi_agree(count * \mpi_extent(datatype));
[1b7d18d]12 @ requires 0 < count && count * \mpi_extent(datatype) < DATA_LIMIT;
[5b6be95]13 @ requires \mpi_valid(buf, count, datatype);
[1b7d18d]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;
[9074a6e]19 @*/
[5b6be95]20int broadcast(void * buf, int count,
[9074a6e]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);
[1b7d18d]27 printf("my rank:%d, root:%d\n", rank, root);
[9074a6e]28 if (rank == root) {
29 for (int i = 0; i < nprocs; i++)
30 if (i != root)
[5b6be95]31 MPI_Send(buf, count, datatype, i, tag, comm);
[9074a6e]32 } else
[5b6be95]33 MPI_Recv(buf, count, datatype, root, tag, comm,
[9074a6e]34 MPI_STATUS_IGNORE);
35 return 0;
36}
Note: See TracBrowser for help on using the repository browser.