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

1.23 2.0 main test-branch
Last change on this file since d01ddb3 was 08f1543, checked in by Ziqing Luo <ziqing@…>, 11 years ago

fixed prolems in ring examples. Add bad ring examples. Add a if-condition for checking potential deadlock in libcommenabler

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2235 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 //$atom {
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 //$atom {
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
66 sendsize = sendcount * sizeofDatatype(sendtype);
67 recvsize = recvcount * sizeofDatatype(recvtype);
68 out = $message_pack(__rank, dest, sendtag, sendbuf, sendsize);
69 $choose {
70 $when (1){
71 $comm_enqueue(comm, out);
72 in = $comm_dequeue(comm, source, recvtag);
73 }
74 $when (1){
75 in = $comm_dequeue(comm, source, recvtag);
76 $comm_enqueue(comm, out);
77 }
78 }
79 $message_unpack(in, recvbuf, recvsize);
80 if (status != MPI_STATUS_IGNORE) {
81 status->MPI_SOURCE = in.source;
82 status->MPI_TAG = in.tag;
83 status->size = in.size;
84 }
85}
86
87$when (__start);
Note: See TracBrowser for help on using the repository browser.