source: CIVL/examples/concurrency/mp_proc2.cvh@ bd7a43e

main test-branch
Last change on this file since bd7a43e 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
Line 
1#include <civlc.cvh>
2
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
18int MPI_Comm_size(MPI_Comm comm, int *size) {
19 *size = $comm_size(comm);
20 return 0;
21}
22
23int MPI_Comm_rank(MPI_Comm comm, int* rank) {
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
27 *rank = $comm_place(comm);
28 return 0;
29}
30
31int MPI_Send(void *buf, int count, MPI_Datatype datatype,
32 int dest, int tag, MPI_Comm comm) {
33 //$atomic {
34 int size;
35
36 size = sizeofDatatype(datatype);
37 $message out = $message_pack(__rank, dest, tag, buf, size);
38 $comm_enqueue(comm, out);
39 //}
40 return 0;
41}
42
43int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
44 int source, int tag, MPI_Comm comm, MPI_Status *status) {
45 $message in = $comm_dequeue(comm, source, tag);
46 //$atomic {
47 int size;
48
49 size = sizeofDatatype(datatype);
50 $message_unpack(in, buf, size);
51 if (status != MPI_STATUS_IGNORE) {
52 status->MPI_SOURCE = in.source;
53 status->MPI_TAG = in.tag;
54 status->size = in.size;
55 }
56 //}
57 return 0;
58}
59
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;
65 _Bool probe;
66
67 sendsize = sendcount * sizeofDatatype(sendtype);
68 recvsize = recvcount * sizeofDatatype(recvtype);
69 out = $message_pack(__rank, dest, sendtag, sendbuf, sendsize);
70 probe = $comm_probe(comm, source, recvtag);
71 $choose {
72 $when (1){
73 $comm_enqueue(comm, out);
74 in = $comm_dequeue(comm, source, recvtag);
75 }
76 $when (probe){
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
89$when (__start);
Note: See TracBrowser for help on using the repository browser.