source: CIVL/examples/contracts/contractsMPI/civl_mpi_collectives/gather-bad_impl.c

2.0
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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