| | 1 | = Message Passing = |
| | 2 | |
| | 3 | First attempt: |
| | 4 | |
| | 5 | {{{ |
| | 6 | $input int NPROCS; |
| | 7 | $assume NPROCS >= 1; |
| | 8 | $scope top; |
| | 9 | $heap mp_heap; |
| | 10 | $proc procs[NPROCS]; |
| | 11 | |
| | 12 | typedef struct Message { |
| | 13 | struct Message *<top> next; |
| | 14 | struct Message *<top> prev; |
| | 15 | int tag; |
| | 16 | int size; |
| | 17 | void *<top> data; |
| | 18 | } Message; |
| | 19 | |
| | 20 | typedef struct Comm { |
| | 21 | Message *<top> buf_front[NPROCS][NPROCS]; |
| | 22 | Message *<top> buf_back[NPROCS][NPROCS]; |
| | 23 | } Comm; |
| | 24 | |
| | 25 | Comm _Comm_world; |
| | 26 | |
| | 27 | Comm *<top> COMM_WORLD = &_Comm_world; |
| | 28 | |
| | 29 | void init() { |
| | 30 | for (int i=0; i<NPROCS; i++) |
| | 31 | procs[i] = $spawn proc(i); |
| | 32 | for (int i=0; i<NPROCS; i++) |
| | 33 | for (int j=0; j<NPROCS; j++) { |
| | 34 | COMM_WORLD->buf_front[i][j] = NULL; |
| | 35 | COMM_WORLD->buf_back[i][j] = NULL; |
| | 36 | } |
| | 37 | |
| | 38 | |
| | 39 | |
| | 40 | |
| | 41 | |
| | 42 | |
| | 43 | }}} |