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
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) {
[1450740]33 //$atom {
[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);
[1450740]46 //$atom {
[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;
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
[18cad8a]87$when (__start);
Note: See TracBrowser for help on using the repository browser.