source: CIVL/examples/contracts/contractsMPI/scatter.c@ 5aff938

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 5aff938 was 5aff938, checked in by Ziqing Luo <ziqing@…>, 10 years ago

add Array Lambda implementation for non-concrete array slicing, it makes gather.c pass though it's very slow

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

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