Changes between Version 3 and Version 4 of MessagePassing
- Timestamp:
- 07/11/13 20:41:11 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MessagePassing
v3 v4 4 4 5 5 {{{ 6 7 #define MPI_ANY_SOURCE -1 8 #define MPI_ANY_TAG -2 9 #define MPI_INT 1 10 #define MPI_FLOAT 2 11 #define MPI_DOUBLE 3 12 // etc. 13 6 14 $input int NPROCS; 7 15 $assume NPROCS >= 1; … … 13 21 * Each queue is a doubly-linked list of Message objects. 14 22 */ 15 typedef struct M essage {16 struct M essage *<top> next;17 struct M essage *<top> prev;23 typedef struct MPI_Message { 24 struct MPI_Message *<top> next; 25 struct MPI_Message *<top> prev; 18 26 int tag; 19 27 int size; 20 28 void *<top> data; 21 } M essage;29 } MPI_Message; 22 30 23 typedef struct Comm_struct {24 M essage *<top> buf_front[NPROCS][NPROCS];25 M essage *<top> buf_back[NPROCS][NPROCS];26 } Comm_struct;31 typedef struct MPI_Comm_struct { 32 MPI_Message *<top> buf_front[NPROCS][NPROCS]; 33 MPI_Message *<top> buf_back[NPROCS][NPROCS]; 34 } MPI_Comm_struct; 27 35 28 typedef Comm_struct *Comm;36 typedef MPI_Comm_struct *MPI_Comm; 29 37 30 38 /* As in MPI, when a receive returns, this structure … … 32 40 * which you need if you used wildcards, Also size. 33 41 */ 34 typedef struct Status {42 typedef struct MPI_Status { 35 43 int source; 36 44 int tag; 37 45 int size; 38 } Status;46 } MPI_Status; 39 47 40 Comm _Comm_world;48 typedef int MPI_Datatype; 41 49 42 /* Th e user will use COMM_WORLD*/43 Comm *<top> COMM_WORLD = &_Comm_world;50 /* This is the actual MPI Comm world structure */ 51 MPI_Comm_struct MPI_Comm_world_struct; 44 52 45 53 /* The user will use MPI_COMM_WORLD */ 54 MPI_Comm MPI_COMM_WORLD = &MPI_Comm_world_struct; 46 55 47 56 void init() { … … 50 59 for (int i=0; i<NPROCS; i++) 51 60 for (int j=0; j<NPROCS; j++) { 52 COMM_WORLD->buf_front[i][j] = NULL;53 COMM_WORLD->buf_back[i][j] = NULL;61 MPI_COMM_WORLD->buf_front[i][j] = NULL; 62 MPI_COMM_WORLD->buf_back[i][j] = NULL; 54 63 } 55 } 64 } 56 65 57 void send(int source, void *buf, int size, int tag, int dest, Comm comm) { 66 int sizeofDatatype(MPI_Datatype type) { 67 switch (type) { 68 case MPI_INT: return sizeof(int); 69 case MPI_FLOAT: return sizeof(float); 70 case MPI_DOUBLE: return sizeof(double); 71 default: exit(-1); // not yet implemented 72 } 73 } 74 75 void MPI_process(int pid) { 76 77 void MPI_Send(void *buf, int size, int tag, int dest, MPI_Comm comm) { 58 78 // create a message 59 79 Message message; … … 69 89 // can I use a function as a guard? not now 70 90 // can always use busy-wait loop? 71 boolean probe(…) {91 boolean recv_guard(int source, int dest, int tag, Comm comm) { 72 92 73 93 }
