| 103 | | void MPI_Send(int pid, void *buf, int count, MPI_Datatype type, int dest, int tag, MPI_Comm comm) { |
| | 106 | |
| | 107 | // very similar to MPI_Send but takes one extra argument at beginning saying who the sender is: |
| | 108 | void CIVL_Send(int pid, void *buf, int count, MPI_Datatype type, int dest, int tag, MPI_Comm comm) { |
| 109 | | void MPI_Recv(int pid, void *buf, int count, MPI_Datataype type, int source, int tag, MPI_Comm comm, MPI_Status *status) { |
| 110 | | int size = sizeofDatatype(type)*count; |
| | 114 | // note we could define this function this way but it is more efficient to implement |
| | 115 | // as system function: |
| | 116 | struct $comm_recv_pair $comm_recv($comm comm, int source, int dest, int tag) { |
| | 117 | struct $comm_recv_pair result; |
| 116 | | *comm = $comm_dequeue(*comm, source, pid, index); |
| 117 | | status->size = $message_size(m); |
| 118 | | status->source = $message_source(m); |
| 119 | | status->dest = $message_dest(m); |
| 120 | | $message_unpack(m, buf, size); // will throw exception if message too big |
| | 122 | result.msg = $comm_get(*comm, source, pid, index); |
| | 123 | result.comm = $comm_dequeue(*comm, source, dest, index); |
| | 124 | return result; |
| | 128 | // similar to MPI_Recv with extra arg at beginning saying who the receiver is: |
| | 129 | void CIVL_Recv(int pid, void *buf, int count, MPI_Datataype type, int source, int tag, MPI_Comm comm, MPI_Status *status) { |
| | 130 | int size = sizeofDatatype(type)*count; |
| | 131 | struct $comm_recv_pair pair = $comm_recv(*comm, source, pid, tag); |
| | 132 | $message m = pair.msg; |
| | 133 | |
| | 134 | status->size = $message_size(m); |
| | 135 | status->source = $message_source(m); |
| | 136 | status->dest = $message_dest(m); |
| | 137 | $message_unpack(m, buf, size); // will throw exception if message too big |
| | 138 | } |
| | 139 | |
| | 140 | |
| | 142 | // these MPI functions are declared here in the process scope so that they can use the pid |
| | 143 | // could put these in a separate header file which is included here? |
| | 144 | void MPI_Send(void *buf, int count, MPI_Datatype type, int dest, int tag, MPI_Comm comm) { |
| | 145 | CIVL_Send(pid, bug, count, type, dest, tag, comm); |
| | 146 | } |
| | 147 | void MPI_Recv(void *buf, int count, MPI_Datataype type, int source, int tag, MPI_Comm comm, MPI_Status *status) { |
| | 148 | CIVL_Recv(pid, bug, count, type, source, tag, comm, status); |
| | 149 | } |