source: CIVL/examples/contracts/contractsMPI/scatter.c@ 3e02d5cb

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 3e02d5cb was 7f8124c, checked in by Manchun Zheng <zmanchun@…>, 10 years ago

added examples from civl-paper repo

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

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include<mpi.h>
2#include<civl-mpi.cvh>
3#include<civlc.cvh>
4#include<string.h>
5#include<stdio.h>
6
7/*@ \mpi_collective(comm, P2P):
8 @ requires recvcount > 0;
9 @ requires \mpi_agree(root) && \mpi_agree(recvcount)
10 @ && \mpi_agree(recvtype);
11 @ requires \mpi_valid(recvbuf, recvcount, recvtype);
12 @ requires 0 <= root && root < \mpi_comm_size;
13 @ behavior imroot:
14 @ assumes \mpi_comm_rank == root;
15 @ requires sendcount > 0;
16 @ requires \mpi_extent(sendtype) * sendcount ==
17 @ \mpi_extent(recvtype) * recvcount;
18 @ requires \mpi_valid(sendbuf, sendcount * \mpi_comm_size, sendtype);
19 @ ensures \mpi_equals(recvbuf, recvcount, recvtype,
20 @ \mpi_offset(sendbuf, \mpi_comm_rank * sendcount,
21 @ sendtype));
22 @ behavior noroot:
23 @ assumes \mpi_comm_rank != root;
24 @ assigns \mpi_region(recvbuf, recvcount, recvtype);
25 @ ensures \mpi_equals(recvbuf, recvcount, recvtype,
26 @ \mpi_offset(\on(root, sendbuf),
27 recvcount * \mpi_comm_rank, recvtype));
28 */
29int scatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype,
30 void* recvbuf, int recvcount, MPI_Datatype recvtype, int root,
31 MPI_Comm comm){
32 int rank, nprocs;
33 int tag = 999;
34
35 MPI_Comm_rank(comm, &rank);
36 MPI_Comm_size(comm, &nprocs);
37
38 if (rank == root) {
39 void * ptr;
40 int offset;
41
42 ptr = $mpi_pointer_add(sendbuf, root*recvcount, sendtype);
43 memcpy(recvbuf, ptr, sizeofDatatype(recvtype)*recvcount);
44 for(int i=0; i<nprocs; i++){
45 if(i != root) {
46 void * ptr;
47
48 offset = i * sendcount;
49 ptr = $mpi_pointer_add(sendbuf, offset, sendtype);
50 MPI_Send(ptr, sendcount, sendtype, i, tag, comm);
51 }
52 }
53 }else
54 MPI_Recv(recvbuf, recvcount, recvtype,
55 root, tag, comm, MPI_STATUS_IGNORE);
56 return 0;
57}
Note: See TracBrowser for help on using the repository browser.