Changes between Version 1 and Version 2 of MessagePassing


Ignore:
Timestamp:
07/11/13 15:31:56 (13 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MessagePassing

    v1 v2  
    1010$proc procs[NPROCS];
    1111
     12/* There will be one message queue for each pair of prods (i,j).
     13 * Each queue is a doubly-linked list of Message objects.
     14 */
    1215typedef struct Message {
    1316  struct Message *<top> next;
     
    1821} Message;
    1922
    20 typedef struct Comm {
     23typedef struct Comm_struct {
    2124  Message *<top> buf_front[NPROCS][NPROCS];
    2225  Message *<top> buf_back[NPROCS][NPROCS];
    23 } Comm;
     26} Comm_struct;
     27
     28typedef Comm_struct *Comm;
     29
     30/* As in MPI, when a receive returns, this structure
     31 * tells you the source and tag of received message,
     32 * which you need if you used wildcards,  Also size.
     33 */
     34typedef struct Status {
     35  int source;
     36  int tag;
     37  int size;
     38} Status;
    2439
    2540Comm _Comm_world;
    2641
     42/* The user will use COMM_WORLD */
    2743Comm *<top> COMM_WORLD = &_Comm_world;
     44
     45
    2846
    2947void init() {
     
    3553      COMM_WORLD->buf_back[i][j] = NULL;
    3654    }
     55}   
     56
     57void send(int source, void *buf, int size, int tag, int dest, Comm comm) {
     58  // create a message
     59  Message message;
     60
     61  message.tag = tag;
     62  message.size = size;
     63  message.data = $malloc<top>(&mp_heap, size);
     64  memcpy(message.data, buf, size);
     65  // enqueue on comm->buf_front[i][j] …
     66  // update  message.next, message.prev, buf_back[i][j]
     67}
     68
     69// can I use a function as a guard?  not now
     70// can always use busy-wait loop?
     71boolean probe(…) {
     72
     73}
     74
     75void recv(int dest, void *buf, int size, int tag, int source, Comm comm, Status *status) {
     76  Message *message; 
     77  int message_source;
     78  int message_dest;
     79  // search the queue looking for the message
     80  // also set message_source, message_dest;
     81  // and remove message from the queue
    3782 
    38 
    39 
    40 
    41 
     83  if (message.size > size) error…;
     84  memcpy(buf, message.data, message.size);
     85  status->size = message.size;
     86  status->source = message_source;
     87  status->dest = message_dest;
     88  $free(message->data);
     89}
    4290
    4391}}}