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