| [e484c35] | 1 | /* This header file defines standard types and provides
|
|---|
| [7b2a68d] | 2 | * functions and function prototypes used in the CIVL-C language.
|
|---|
| 3 | * It includes civlc-common.h, and then completes many of the
|
|---|
| 4 | * declarations in civlc-common.h.
|
|---|
| [e484c35] | 5 | */
|
|---|
| [8a9124e] | 6 |
|
|---|
| [e484c35] | 7 | #ifdef __CIVLC__
|
|---|
| 8 | #else
|
|---|
| 9 | #define __CIVLC__
|
|---|
| [f6ecaae] | 10 | #include<civlc-common.h>
|
|---|
| [e484c35] | 11 |
|
|---|
| [7b2a68d] | 12 | /* ******************************* Types ******************************* */
|
|---|
| 13 |
|
|---|
| 14 | /* A message formed by $message_pack. Completes the declaration
|
|---|
| 15 | * of this structure type in civlc-common.h */
|
|---|
| [517b138] | 16 | struct __message__ {
|
|---|
| 17 | int source;
|
|---|
| 18 | int dest;
|
|---|
| 19 | int tag;
|
|---|
| 20 | $bundle data;
|
|---|
| 21 | int size;
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| [7b2a68d] | 24 | /* A datatype representing a queue of messages. All message
|
|---|
| 25 | * data is encapsulated inside this value; no external allocation
|
|---|
| 26 | * is used. Completes the declaration of this structure type in
|
|---|
| 27 | * civlc-common.h */
|
|---|
| 28 | struct __queue__ {
|
|---|
| 29 | int length;
|
|---|
| 30 | $message messages[];
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | /* A global communicator datatype which must be operated by local communicators.
|
|---|
| 35 | * This communicator type has the same meaning as the communicator type
|
|---|
| 36 | * in MPI. Completes the declaration of this type in civlc-common.h */
|
|---|
| 37 | struct __gcomm__ {
|
|---|
| 38 | int nprocs; // number of processes
|
|---|
| 39 | _Bool isInit[]; // if the local comm has been initiated
|
|---|
| 40 | $queue buf[][]; // message buffers
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | /* A datatype representing a local communicator which is used for
|
|---|
| 44 | * operating global communicators. The local communicator type has
|
|---|
| 45 | * a handle of a global communicator. This type represents for
|
|---|
| 46 | * a set of processes which have ranks in common.
|
|---|
| 47 | * Completes the declaration of this type in civlc-common.h.
|
|---|
| 48 | */
|
|---|
| 49 | struct __comm__ {
|
|---|
| 50 | int place;
|
|---|
| 51 | $gcomm gcomm;
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | /* A datatype representing a global barrier which must be operated by local
|
|---|
| 55 | * barriers. Completes the declaration of this type in civlc-common.h.
|
|---|
| 56 | */
|
|---|
| 57 | struct __gbarrier__ {
|
|---|
| 58 | int nprocs;
|
|---|
| 59 | $proc proc_map[]; // initialized as all $proc_null.
|
|---|
| 60 | _Bool in_barrier[]; // initialized as all false.
|
|---|
| 61 | int num_in_barrier; // initialized as 0.
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | /* A datatype representing a global barrier which used for
|
|---|
| 65 | * operating global barriers. The local barrier type has
|
|---|
| 66 | * a handle of a global barrier.
|
|---|
| 67 | * Completes the declaration of this type in civlc-common.h.
|
|---|
| 68 | */
|
|---|
| 69 | struct __barrier__ {
|
|---|
| 70 | int place;
|
|---|
| 71 | $gbarrier gbarrier; // initialized as 0.
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | /* Completes the declaration of this type in civlc-common.h */
|
|---|
| 75 | struct __int_iter__ {
|
|---|
| 76 | int size;
|
|---|
| 77 | int content[];
|
|---|
| 78 | int index; //initialized as 0
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | /* ***************************** Functions ***************************** */
|
|---|
| [517b138] | 82 |
|
|---|
| 83 |
|
|---|
| [e484c35] | 84 | /* creates a new message, copying data from the specified buffer */
|
|---|
| 85 | $message $message_pack(int source, int dest, int tag,
|
|---|
| 86 | void *data, int size) {
|
|---|
| 87 | $message result;
|
|---|
| 88 |
|
|---|
| 89 | result.source = source;
|
|---|
| 90 | result.dest = dest;
|
|---|
| 91 | result.tag = tag;
|
|---|
| 92 | result.data = $bundle_pack(data, size);
|
|---|
| 93 | result.size = size;
|
|---|
| 94 | return result;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /* returns the message source */
|
|---|
| 98 | int $message_source($message message) {
|
|---|
| 99 | return message.source;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /* returns the message tag */
|
|---|
| 103 | int $message_tag($message message) {
|
|---|
| 104 | return message.tag;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /* returns the message destination */
|
|---|
| 108 | int $message_dest($message message) {
|
|---|
| 109 | return message.dest;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /* returns the message size */
|
|---|
| 113 | int $message_size($message message) {
|
|---|
| 114 | return message.size;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /* transfers message data to buf, throwing exception if message
|
|---|
| 118 | * size exceeds specified size */
|
|---|
| 119 | void $message_unpack($message message, void *buf, int size) {
|
|---|
| 120 | $bundle_unpack(message.data, buf);
|
|---|
| 121 | $assert(message.size <= size,
|
|---|
| 122 | "Message of size %d exceeds the specified size %d.", message.size, size);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /* Returns the place of the local communicator. This is the same as the
|
|---|
| 126 | * place argument used to create the local communicator. */
|
|---|
| 127 | int $comm_place($comm comm){
|
|---|
| 128 | return comm->place;
|
|---|
| 129 | }
|
|---|
| [c270dae] | 130 |
|
|---|
| 131 | void $barrier_call($barrier barrier) {
|
|---|
| 132 | $barrier_enter(barrier);
|
|---|
| 133 | $barrier_exit(barrier);
|
|---|
| 134 | }
|
|---|
| [f4de9d5] | 135 |
|
|---|
| [e484c35] | 136 | #endif
|
|---|