| 1 | /* This header file contains the data types and function prototypes for
|
|---|
| 2 | * communication.
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #ifdef __COMM__
|
|---|
| 6 | #else
|
|---|
| 7 | #define __COMM__
|
|---|
| 8 |
|
|---|
| 9 | /* includes civlc.cvh because this library references $scope */
|
|---|
| 10 | #include <civlc.cvh>
|
|---|
| 11 | #include <bundle.cvh>
|
|---|
| 12 |
|
|---|
| 13 | /* *********************** Constants *********************** */
|
|---|
| 14 |
|
|---|
| 15 | /* Like MPI_ANY_SOURCE, can be used in probe, seek, dequeue
|
|---|
| 16 | * to match a message with any source */
|
|---|
| 17 | #define $COMM_ANY_SOURCE -1
|
|---|
| 18 |
|
|---|
| 19 | /* Like $COMM_ANY_SOURCE above, except for tags */
|
|---|
| 20 | #define $COMM_ANY_TAG -2
|
|---|
| 21 |
|
|---|
| 22 | /* ********************************* Types ********************************* */
|
|---|
| 23 |
|
|---|
| 24 | /* The message type, declared here as an incomplete
|
|---|
| 25 | * struct type, which is all you need for constructing
|
|---|
| 26 | * the AST. For the complete version, see the CIVL
|
|---|
| 27 | * project.
|
|---|
| 28 | */
|
|---|
| 29 | typedef struct __message__ {
|
|---|
| 30 | int source;
|
|---|
| 31 | int dest;
|
|---|
| 32 | int tag;
|
|---|
| 33 | $bundle data;
|
|---|
| 34 | int size;
|
|---|
| 35 | } $message;
|
|---|
| 36 |
|
|---|
| 37 | /* A datatype representing a queue of messages. All message
|
|---|
| 38 | * data is encapsulated inside this value; no external allocation
|
|---|
| 39 | * is used. */
|
|---|
| 40 | typedef struct __queue__ $queue;
|
|---|
| 41 |
|
|---|
| 42 | /* A global communicator datatype which must be operated by local communicators.
|
|---|
| 43 | * This communicator type has the same meaning as the communicator type in MPI
|
|---|
| 44 | * standards*/
|
|---|
| 45 | typedef struct __gcomm__ * $gcomm;
|
|---|
| 46 |
|
|---|
| 47 | /* A datatype representing a local communicator which is used for
|
|---|
| 48 | * operating global communicators. The local communicator type has
|
|---|
| 49 | * a handle of a global communicator. This type represents for
|
|---|
| 50 | * a set of processes which have ranks in common.
|
|---|
| 51 | */
|
|---|
| 52 | typedef struct __comm__ * $comm;
|
|---|
| 53 |
|
|---|
| 54 | /* ************************* Functions of Message ************************** */
|
|---|
| 55 |
|
|---|
| 56 | /* creates a new message, copying data from the specified buffer */
|
|---|
| 57 | $message $message_pack(int source, int dest, int tag, void *data, int size);
|
|---|
| 58 |
|
|---|
| 59 | /* returns the message source */
|
|---|
| 60 | int $message_source($message message);
|
|---|
| 61 |
|
|---|
| 62 | /* returns the message tag */
|
|---|
| 63 | int $message_tag($message message) ;
|
|---|
| 64 |
|
|---|
| 65 | /* returns the message destination */
|
|---|
| 66 | int $message_dest($message message) ;
|
|---|
| 67 |
|
|---|
| 68 | /* returns the message size */
|
|---|
| 69 | int $message_size($message message);
|
|---|
| 70 |
|
|---|
| 71 | /* transfers message data to buf, throwing exception if message
|
|---|
| 72 | * size exceeds specified size */
|
|---|
| 73 | void $message_unpack($message message, void *buf, int size);
|
|---|
| 74 |
|
|---|
| 75 | /* ************************** Functions of $gcomm ************************** */
|
|---|
| 76 |
|
|---|
| 77 | /* Creates a new global communicator object and returns a handle to it.
|
|---|
| 78 | * The global communicator will have size communication places. The
|
|---|
| 79 | * global communicator defines a communication "universe" and encompasses
|
|---|
| 80 | * message buffers and all other components of the state associated to
|
|---|
| 81 | * message-passing. The new object will be allocated in the given scope. */
|
|---|
| 82 | $gcomm $gcomm_create($scope scope, int size);
|
|---|
| 83 |
|
|---|
| 84 | /* De-allocation a __gcomm__ object */
|
|---|
| 85 | void $gcomm_destroy($gcomm gcomm);
|
|---|
| 86 |
|
|---|
| 87 | /* Returns $true iff gcomm points to a valid object. */
|
|---|
| 88 | _Bool $gcomm_defined($gcomm gcomm);
|
|---|
| 89 |
|
|---|
| 90 | /* *************************** Functions of $comm ************************** */
|
|---|
| 91 |
|
|---|
| 92 | /* Creates a new local communicator object and returns a handle to it.
|
|---|
| 93 | * The new communicator will be affiliated with the specified global
|
|---|
| 94 | * communicator. This local communicator handle will be used as an
|
|---|
| 95 | * argument in most message-passing functions. The place must be in
|
|---|
| 96 | * [0,size-1] and specifies the place in the global communication universe
|
|---|
| 97 | * that will be occupied by the local communicator. The local communicator
|
|---|
| 98 | * handle may be used by more than one process, but all of those
|
|---|
| 99 | * processes will be viewed as occupying the same place.
|
|---|
| 100 | * Only one call to $comm_create may occur for each gcomm-place pair.
|
|---|
| 101 | * The new object will be allocated in the given scope. */
|
|---|
| 102 | $comm $comm_create($scope scope, $gcomm gcomm, int place);
|
|---|
| 103 |
|
|---|
| 104 | /* De-allocation a __comm__ object */
|
|---|
| 105 | void $comm_destroy($comm comm);
|
|---|
| 106 |
|
|---|
| 107 | /* Returns the size (number of places) in the global communicator associated
|
|---|
| 108 | * to the given comm. */
|
|---|
| 109 | int $comm_size($comm comm);
|
|---|
| 110 |
|
|---|
| 111 | /* Returns the place of the local communicator. This is the same as the
|
|---|
| 112 | * place argument used to create the local communicator. */
|
|---|
| 113 | int $comm_place($comm comm);
|
|---|
| 114 |
|
|---|
| 115 | /* Adds the message to the appropriate message queue in the communication
|
|---|
| 116 | * universe specified by the comm. The source of the message must equal
|
|---|
| 117 | * the place of the comm. */
|
|---|
| 118 | void $comm_enqueue($comm comm, $message message);
|
|---|
| 119 |
|
|---|
| 120 | /* Returns true iff a matching message exists in the communication universe
|
|---|
| 121 | * specified by the comm. A message matches the arguments if the destination
|
|---|
| 122 | * of the message is the place of the comm, and the sources and tags match. */
|
|---|
| 123 | _Bool $comm_probe($comm comm, int source, int tag);
|
|---|
| 124 |
|
|---|
| 125 | /* Finds the first matching message and returns it without modifying
|
|---|
| 126 | * the communication universe. If no matching message exists, returns a message
|
|---|
| 127 | * with source, dest, and tag all negative. */
|
|---|
| 128 | $message $comm_seek($comm comm, int source, int tag);
|
|---|
| 129 |
|
|---|
| 130 | /* Finds the first matching message, removes it from the communicator,
|
|---|
| 131 | * and returns the message */
|
|---|
| 132 | $message $comm_dequeue($comm comm, int source, int tag);
|
|---|
| 133 |
|
|---|
| 134 | /* Returns $true iff comm points to a valid object. */
|
|---|
| 135 | _Bool $comm_defined($comm comm);
|
|---|
| 136 |
|
|---|
| 137 | #endif
|
|---|