Changes between Version 22 and Version 23 of MessagePassing


Ignore:
Timestamp:
09/13/13 20:10:20 (13 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MessagePassing

    v22 v23  
    6060
    6161{{{
     62
     63// most of this stuff could go in a header file which is included here:
     64
    6265#define MPI_ANY_SOURCE $COMM_ANY_SOURCE
    6366#define MPI_ANY_TAG $COMM_ANY_TAG
     
    101104}
    102105
    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:
     108void CIVL_Send(int pid, void *buf, int count, MPI_Datatype type, int dest, int tag, MPI_Comm comm) {
    104109  $message m = $message_pack(pid, dest, tag, buf, sizeofDatatype(type)*count);
    105110
     
    107112}
    108113
    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:
     116struct $comm_recv_pair $comm_recv($comm comm, int source, int dest, int tag) {
     117  struct $comm_recv_pair result;
    111118
    112   when ($comm_probe(*comm, source, pid, tag)) {
     119  when ($comm_probe(*comm, source, dest, tag)) {
    113120    int index = $comm_seek(*comm, source, pid, tag);
    114     $message m = $comm_get(*comm, source, pid, index);
    115121
    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;
    121125  }
    122126}
    123127
     128// similar to MPI_Recv with extra arg at beginning saying who the receiver is:
     129void 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
    124141void MPI_process(int pid) {
     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  }
    125150  ...
    126151  MPI_Comm_init(MPI_COMM_WORLD);