| 1 | /* This header file contains the data types and function prototypes for
|
|---|
| 2 | * communication.
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #ifndef _COMM_
|
|---|
| 6 | #define _COMM_
|
|---|
| 7 |
|
|---|
| 8 | /* includes civlc.cvh because this library references $scope */
|
|---|
| 9 | #include <civlc.cvh>
|
|---|
| 10 | #include <bundle.cvh>
|
|---|
| 11 | #pragma CIVL ACSL
|
|---|
| 12 | /* *********************** Constants *********************** */
|
|---|
| 13 |
|
|---|
| 14 | /* Like MPI_ANY_SOURCE, can be used in probe, seek, dequeue
|
|---|
| 15 | * to match a message with any source */
|
|---|
| 16 | #define $COMM_ANY_SOURCE -1
|
|---|
| 17 |
|
|---|
| 18 | /* Like $COMM_ANY_SOURCE above, except for tags */
|
|---|
| 19 | #define $COMM_ANY_TAG -2
|
|---|
| 20 |
|
|---|
| 21 | /* ********************************* Types ********************************* */
|
|---|
| 22 |
|
|---|
| 23 | /* The message type, declared here as an incomplete
|
|---|
| 24 | * struct type, which is all you need for constructing
|
|---|
| 25 | * the AST. For the complete version, see the CIVL
|
|---|
| 26 | * project.
|
|---|
| 27 | */
|
|---|
| 28 | typedef struct _message {
|
|---|
| 29 | int source;
|
|---|
| 30 | int dest;
|
|---|
| 31 | int tag;
|
|---|
| 32 | $bundle data;
|
|---|
| 33 | int size;
|
|---|
| 34 | } $message;
|
|---|
| 35 |
|
|---|
| 36 | /* A datatype representing a queue of messages. All message
|
|---|
| 37 | * data is encapsulated inside this value; no external allocation
|
|---|
| 38 | * is used. */
|
|---|
| 39 | typedef struct _queue $queue;
|
|---|
| 40 |
|
|---|
| 41 | /* A global communicator datatype which must be operated by local communicators.
|
|---|
| 42 | * This communicator type has the same meaning as the communicator type in MPI
|
|---|
| 43 | * standards*/
|
|---|
| 44 | typedef struct _gcomm * $gcomm;
|
|---|
| 45 |
|
|---|
| 46 | /* A datatype representing a local communicator which is used for
|
|---|
| 47 | * operating global communicators. The local communicator type has
|
|---|
| 48 | * a handle of a global communicator. This type represents for
|
|---|
| 49 | * a set of processes which have ranks in common.
|
|---|
| 50 | */
|
|---|
| 51 | typedef struct _comm * $comm;
|
|---|
| 52 |
|
|---|
| 53 | #define $comm_null NULL
|
|---|
| 54 |
|
|---|
| 55 | /* ************************* Functions of Message ************************** */
|
|---|
| 56 |
|
|---|
| 57 | /* creates a new message, copying data from the specified buffer */
|
|---|
| 58 | /*@
|
|---|
| 59 | @ depends_on \access(data);
|
|---|
| 60 | @ executes_when \true;
|
|---|
| 61 | @*/
|
|---|
| 62 | $atomic_f $message $message_pack(int source, int dest, int tag, const void *data, int size);
|
|---|
| 63 |
|
|---|
| 64 | /* returns the message source */
|
|---|
| 65 | /*@ pure;
|
|---|
| 66 | @ depends_on \nothing;
|
|---|
| 67 | @ executes_when \true;
|
|---|
| 68 | @*/
|
|---|
| 69 | $atomic_f int $message_source($message message);
|
|---|
| 70 |
|
|---|
| 71 | /* returns the message tag */
|
|---|
| 72 | /*@ pure;
|
|---|
| 73 | @ depends_on \nothing;
|
|---|
| 74 | @ executes_when \true;
|
|---|
| 75 | @*/
|
|---|
| 76 | $atomic_f int $message_tag($message message) ;
|
|---|
| 77 |
|
|---|
| 78 | /* returns the message destination */
|
|---|
| 79 | /*@ pure;
|
|---|
| 80 | @ depends_on \nothing;
|
|---|
| 81 | @ executes_when \true;
|
|---|
| 82 | @*/
|
|---|
| 83 | $atomic_f int $message_dest($message message) ;
|
|---|
| 84 |
|
|---|
| 85 | /* returns the message size */
|
|---|
| 86 | /*@ pure;
|
|---|
| 87 | @ depends_on \nothing;
|
|---|
| 88 | @ executes_when \true;
|
|---|
| 89 | @*/
|
|---|
| 90 | $atomic_f int $message_size($message message);
|
|---|
| 91 |
|
|---|
| 92 | /* transfers message data to buf, throwing exception if message
|
|---|
| 93 | * size exceeds specified size */
|
|---|
| 94 | /*@ depends_on \access(buf);
|
|---|
| 95 | @ executes_when \true;
|
|---|
| 96 | @*/
|
|---|
| 97 | $atomic_f void $message_unpack($message message, void *buf, int size);
|
|---|
| 98 |
|
|---|
| 99 | /* ************************** Functions of $gcomm ************************** */
|
|---|
| 100 |
|
|---|
| 101 | /* Creates a new global communicator object and returns a handle to it.
|
|---|
| 102 | * The global communicator will have size communication places. The
|
|---|
| 103 | * global communicator defines a communication "universe" and encompasses
|
|---|
| 104 | * message buffers and all other components of the state associated to
|
|---|
| 105 | * message-passing. The new object will be allocated in the given scope. */
|
|---|
| 106 | /*@ depends_on \nothing;
|
|---|
| 107 | @ assigns \nothing;
|
|---|
| 108 | @ reads \nothing;
|
|---|
| 109 | @*/
|
|---|
| 110 | $atomic_f $gcomm $gcomm_create($scope scope, int size);
|
|---|
| 111 |
|
|---|
| 112 | /* De-allocation a __gcomm__ object. Returns the number of messages
|
|---|
| 113 | * still remaining in the communicator.
|
|---|
| 114 | *
|
|---|
| 115 | * Parameter gcomm: the __gcomm__ object that is going to be de-allocated.
|
|---|
| 116 | * Parameter junkMsgs: Output argument, a pointer to a CIVL-C sequence ($seq)
|
|---|
| 117 | * of $messages.
|
|---|
| 118 | */
|
|---|
| 119 | /*@ depends_on \access(junkMsgs), \access(gcomm);
|
|---|
| 120 | @ assigns junkMsgs, gcomm;
|
|---|
| 121 | @*/
|
|---|
| 122 | $atomic_f int $gcomm_destroy($gcomm gcomm, void * junkMsgs);
|
|---|
| 123 |
|
|---|
| 124 | /* Returns $true iff gcomm points to a valid object. */
|
|---|
| 125 | //_Bool $gcomm_defined($gcomm gcomm);
|
|---|
| 126 |
|
|---|
| 127 | $atomic_f void $gcomm_dup($comm comm, $comm newcomm);
|
|---|
| 128 |
|
|---|
| 129 | /* *************************** Functions of $comm ************************** */
|
|---|
| 130 |
|
|---|
| 131 | /* Creates a new local communicator object and returns a handle to it.
|
|---|
| 132 | * The new communicator will be affiliated with the specified global
|
|---|
| 133 | * communicator. This local communicator handle will be used as an
|
|---|
| 134 | * argument in most message-passing functions. The place must be in
|
|---|
| 135 | * [0,size-1] and specifies the place in the global communication universe
|
|---|
| 136 | * that will be occupied by the local communicator. The local communicator
|
|---|
| 137 | * handle may be used by more than one process, but all of those
|
|---|
| 138 | * processes will be viewed as occupying the same place.
|
|---|
| 139 | * Only one call to $comm_create may occur for each gcomm-place pair.
|
|---|
| 140 | * The new object will be allocated in the given scope. */
|
|---|
| 141 | /*@ depends_on \nothing;
|
|---|
| 142 | @ reads gcomm;
|
|---|
| 143 | @ assigns gcomm;
|
|---|
| 144 | @*/
|
|---|
| 145 | $atomic_f $comm $comm_create($scope scope, $gcomm gcomm, int place);
|
|---|
| 146 |
|
|---|
| 147 | /* De-allocation a __comm__ object */
|
|---|
| 148 | /*@ depends_on \access(comm);
|
|---|
| 149 | @ assigns comm;
|
|---|
| 150 | @ reads \nothing;
|
|---|
| 151 | @*/
|
|---|
| 152 | $atomic_f void $comm_destroy($comm comm);
|
|---|
| 153 |
|
|---|
| 154 | /* Returns the size (number of places) in the global communicator associated
|
|---|
| 155 | * to the given comm. */
|
|---|
| 156 | /*@ pure;
|
|---|
| 157 | @ depends_on \nothing;
|
|---|
| 158 | @*/
|
|---|
| 159 | $atomic_f int $comm_size($comm comm);
|
|---|
| 160 |
|
|---|
| 161 | /* Returns the place of the local communicator. This is the same as the
|
|---|
| 162 | * place argument used to create the local communicator. */
|
|---|
| 163 | /*@ pure;
|
|---|
| 164 | @ depends_on \nothing;
|
|---|
| 165 | @ executes_when \true;
|
|---|
| 166 | @*/
|
|---|
| 167 | $atomic_f int $comm_place($comm comm);
|
|---|
| 168 |
|
|---|
| 169 | /* Adds the message to the appropriate message queue in the
|
|---|
| 170 | communication universe specified by the comm. The source of the
|
|---|
| 171 | message must equal the place of the comm.
|
|---|
| 172 |
|
|---|
| 173 | This function is a no-op if the parameter "comm" has value equal to "$comm_null".
|
|---|
| 174 | */
|
|---|
| 175 | /*@ depends_on \access(comm);
|
|---|
| 176 | @ executes_when \true;
|
|---|
| 177 | @*/
|
|---|
| 178 | $system void $comm_enqueue($comm comm, $message message);
|
|---|
| 179 |
|
|---|
| 180 | /* Returns true iff a matching message exists in the communication universe
|
|---|
| 181 | * specified by the comm. A message matches the arguments if the destination
|
|---|
| 182 | * of the message is the place of the comm, and the sources and tags match. */
|
|---|
| 183 | /*@
|
|---|
| 184 | @
|
|---|
| 185 | @ executes_when \true;
|
|---|
| 186 | @*/
|
|---|
| 187 | $system $state_f _Bool $comm_probe($comm comm, int source, int tag);
|
|---|
| 188 |
|
|---|
| 189 | /* Finds the first matching message and returns it without modifying
|
|---|
| 190 | * the communication universe. If no matching message exists, returns a message
|
|---|
| 191 | * with source, dest, and tag all negative. */
|
|---|
| 192 | /*@ pure;
|
|---|
| 193 | @ depends_on \access(comm);
|
|---|
| 194 | @ executes_when \true;
|
|---|
| 195 | @*/
|
|---|
| 196 | $system $message $comm_seek($comm comm, int source, int tag);
|
|---|
| 197 |
|
|---|
| 198 | /* Finds the first matching message, removes it from the communicator,
|
|---|
| 199 | and returns the message
|
|---|
| 200 |
|
|---|
| 201 | This function is a no-op if the parameter "comm" has value equal to "$comm_null".
|
|---|
| 202 | */
|
|---|
| 203 | /*@
|
|---|
| 204 | @ executes_when $comm_probe(comm, source, tag);
|
|---|
| 205 | @ behavior determ:
|
|---|
| 206 | @ assumes source != $COMM_ANY_SOURCE;
|
|---|
| 207 | @ depends_on \access(comm);
|
|---|
| 208 | @ behavior nondeterm:
|
|---|
| 209 | @ assumes source == $COMM_ANY_SOURCE;
|
|---|
| 210 | @*/
|
|---|
| 211 | $system $message $comm_dequeue($comm comm, int source, int tag);
|
|---|
| 212 |
|
|---|
| 213 | /*@ pure;
|
|---|
| 214 | @ depends_on \nothing;
|
|---|
| 215 | @ executes_when \true;
|
|---|
| 216 | @*/
|
|---|
| 217 | $system $state_f _Bool $comm_empty_in($comm );
|
|---|
| 218 |
|
|---|
| 219 | /*@ pure;
|
|---|
| 220 | @ depends_on \nothing;
|
|---|
| 221 | @ executes_when \true;
|
|---|
| 222 | @*/
|
|---|
| 223 | $system $state_f _Bool $comm_empty_out($comm );
|
|---|
| 224 |
|
|---|
| 225 | /* Returns $true iff comm points to a valid object. */
|
|---|
| 226 | //_Bool $comm_defined($comm comm);
|
|---|
| 227 |
|
|---|
| 228 | #endif
|
|---|