source:
CIVL/examples/concurrency/mp_root2.cvh@
dccd621
| Last change on this file since dccd621 was 0baeebd, checked in by , 11 years ago | |
|---|---|
|
|
| File size: 1.3 KB | |
| Rev | Line | |
|---|---|---|
| [18cad8a] | 1 | #define MPI_ANY_SOURCE $COMM_ANY_SOURCE |
| 2 | #define MPI_ANY_TAG $COMM_ANY_TAG | |
| [0baeebd] | 3 | $input int NPROCS = 3; |
| [18cad8a] | 4 | $proc __procs[NPROCS]; |
| 5 | _Bool __start = 0; | |
| [c905758] | 6 | $gcomm __MPI_Comm_World = $gcomm_create($root, NPROCS); |
| 7 | ||
| 8 | typedef $comm MPI_Comm; | |
| [18cad8a] | 9 | |
| 10 | typedef int MPI_Datatype; | |
| 11 | ||
| 12 | #define MPI_INT 1 | |
| 13 | #define MPI_DOUBLE 2 | |
| 14 | #define MPI_FLOAT 3 | |
| 15 | #define MPI_CHAR 4 | |
| 16 | ||
| 17 | struct __MPI_Status { | |
| [e51fd2f] | 18 | int MPI_SOURCE; |
| 19 | int MPI_TAG; | |
| 20 | int MPI_ERROR; | |
| [18cad8a] | 21 | int size; |
| 22 | }; | |
| 23 | ||
| 24 | typedef struct __MPI_Status MPI_Status; | |
| 25 | ||
| [1450740] | 26 | //MPI_Status __MPI_Status_ignore; |
| [e51fd2f] | 27 | |
| [1450740] | 28 | MPI_Status *MPI_STATUS_IGNORE = (MPI_Status*) NULL; |
| [e51fd2f] | 29 | |
| 30 | int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, | |
| 31 | int *count) { | |
| 32 | int size; | |
| 33 | ||
| 34 | switch (datatype) { | |
| 35 | case MPI_INT: | |
| 36 | size = sizeof(int); | |
| 37 | break; | |
| 38 | case MPI_FLOAT: | |
| 39 | size = sizeof(float); | |
| 40 | break; | |
| 41 | case MPI_DOUBLE: | |
| 42 | size = sizeof(double); | |
| 43 | break; | |
| 44 | case MPI_CHAR: | |
| 45 | size = sizeof(char); | |
| 46 | break; | |
| 47 | default: | |
| 48 | printf("Unsupported datatype %d\n", datatype); | |
| [09b9231b] | 49 | $assert($false); |
| [e51fd2f] | 50 | } |
| [09b9231b] | 51 | $assert(status->size % size == 0); |
| [e51fd2f] | 52 | *count = status->size / size; |
| 53 | return 0; | |
| 54 | } | |
| 55 | ||
| 56 | void MPI_Process (int __rank); | |
| [18cad8a] | 57 | |
| 58 | void init() { | |
| 59 | for (int i=0; i<NPROCS; i++) | |
| 60 | __procs[i] = $spawn MPI_Process(i); | |
| 61 | __start=1; | |
| 62 | } | |
| 63 | ||
| 64 | void finalize() { | |
| 65 | for (int i=0; i<NPROCS; i++) | |
| [a82987f] | 66 | $wait(__procs[i]); |
| [ef22d03] | 67 | $gcomm_destroy(__MPI_Comm_World); |
| [18cad8a] | 68 | } |
| 69 | ||
| 70 | void main() { | |
| [c905758] | 71 | init(); |
| 72 | finalize(); | |
| [18cad8a] | 73 | } |
Note:
See TracBrowser
for help on using the repository browser.
