source: CIVL/examples/contracts/contractsMPI/gather.c@ b5cfaf6

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

commit progress

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

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