Changes between Version 1 and Version 2 of MessagePassing
- Timestamp:
- 07/11/13 15:31:56 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MessagePassing
v1 v2 10 10 $proc procs[NPROCS]; 11 11 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 */ 12 15 typedef struct Message { 13 16 struct Message *<top> next; … … 18 21 } Message; 19 22 20 typedef struct Comm {23 typedef struct Comm_struct { 21 24 Message *<top> buf_front[NPROCS][NPROCS]; 22 25 Message *<top> buf_back[NPROCS][NPROCS]; 23 } Comm; 26 } Comm_struct; 27 28 typedef 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 */ 34 typedef struct Status { 35 int source; 36 int tag; 37 int size; 38 } Status; 24 39 25 40 Comm _Comm_world; 26 41 42 /* The user will use COMM_WORLD */ 27 43 Comm *<top> COMM_WORLD = &_Comm_world; 44 45 28 46 29 47 void init() { … … 35 53 COMM_WORLD->buf_back[i][j] = NULL; 36 54 } 55 } 56 57 void 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? 71 boolean probe(…) { 72 73 } 74 75 void 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 37 82 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 } 42 90 43 91 }}}
