source: CIVL/examples/concurrency/mp_proc2.cvh

main
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.2 KB
RevLine 
[3ff27cf]1#include <civlc.cvh>
[e51fd2f]2
[08f1543]3int sizeofDatatype(MPI_Datatype datatype) {
4 switch (datatype) {
5 case MPI_INT:
6 return sizeof(int);
7 case MPI_FLOAT:
8 return sizeof(float);
9 case MPI_DOUBLE:
10 return sizeof(double);
11 case MPI_CHAR:
12 return sizeof(char);
13 default:
14 $assert(0, "Unreachable");
15 }
16}
17
[e51fd2f]18int MPI_Comm_size(MPI_Comm comm, int *size) {
[c905758]19 *size = $comm_size(comm);
[e51fd2f]20 return 0;
21}
22
[c905758]23int MPI_Comm_rank(MPI_Comm comm, int* rank) {
[e51fd2f]24 // this only works for MPI_COMM_WORLD.
25 // for multiple communicators, you will need
26 // a map (array) from PID to rank for each comm
[68f2754]27 *rank = $comm_place(comm);
[e51fd2f]28 return 0;
29}
30
31int MPI_Send(void *buf, int count, MPI_Datatype datatype,
32 int dest, int tag, MPI_Comm comm) {
[0c90cbf]33 //$atomic {
[18cad8a]34 int size;
35
[08f1543]36 size = sizeofDatatype(datatype);
[e51fd2f]37 $message out = $message_pack(__rank, dest, tag, buf, size);
[18cad8a]38 $comm_enqueue(comm, out);
[1450740]39 //}
[e51fd2f]40 return 0;
[18cad8a]41}
42
[e51fd2f]43int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
44 int source, int tag, MPI_Comm comm, MPI_Status *status) {
[c905758]45 $message in = $comm_dequeue(comm, source, tag);
[0c90cbf]46 //$atomic {
[18cad8a]47 int size;
48
[08f1543]49 size = sizeofDatatype(datatype);
[18cad8a]50 $message_unpack(in, buf, size);
[e51fd2f]51 if (status != MPI_STATUS_IGNORE) {
52 status->MPI_SOURCE = in.source;
53 status->MPI_TAG = in.tag;
54 status->size = in.size;
55 }
[1450740]56 //}
[e51fd2f]57 return 0;
[18cad8a]58}
59
[08f1543]60int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
61 int dest, int sendtag, void *recvbuf, int recvcount, MPI_Datatype recvtype,
62 int source, int recvtag, MPI_Comm comm, MPI_Status *status){
63 int sendsize, recvsize;
64 $message out , in;
[fc1850d]65 _Bool probe;
[08f1543]66
67 sendsize = sendcount * sizeofDatatype(sendtype);
68 recvsize = recvcount * sizeofDatatype(recvtype);
69 out = $message_pack(__rank, dest, sendtag, sendbuf, sendsize);
[fc1850d]70 probe = $comm_probe(comm, source, recvtag);
[08f1543]71 $choose {
72 $when (1){
73 $comm_enqueue(comm, out);
74 in = $comm_dequeue(comm, source, recvtag);
75 }
[fc1850d]76 $when (probe){
[08f1543]77 in = $comm_dequeue(comm, source, recvtag);
78 $comm_enqueue(comm, out);
79 }
80 }
81 $message_unpack(in, recvbuf, recvsize);
82 if (status != MPI_STATUS_IGNORE) {
83 status->MPI_SOURCE = in.source;
84 status->MPI_TAG = in.tag;
85 status->size = in.size;
86 }
87}
88
[18cad8a]89$when (__start);
Note: See TracBrowser for help on using the repository browser.