| 1 | #include <civlc.cvh>
|
|---|
| 2 | /* This file completes the definitions of some types and functions
|
|---|
| 3 | * for communication, which are declared in comm-common.cvh.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #ifdef __CIVLC_COMM__
|
|---|
| 7 | #else
|
|---|
| 8 | #define __CIVLC_COMM__
|
|---|
| 9 |
|
|---|
| 10 | #include<comm.cvh>
|
|---|
| 11 |
|
|---|
| 12 | /* *********************** Types *********************** */
|
|---|
| 13 |
|
|---|
| 14 | /* A datatype representing a queue of messages. All message
|
|---|
| 15 | * data is encapsulated inside this value; no external allocation
|
|---|
| 16 | * is used. Completes the declaration of this structure type in
|
|---|
| 17 | * civlc-common.h */
|
|---|
| 18 | struct __queue__ {
|
|---|
| 19 | int length;
|
|---|
| 20 | $message messages[];
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | /* A global communicator datatype which must be operated by local communicators.
|
|---|
| 25 | * This communicator type has the same meaning as the communicator type
|
|---|
| 26 | * in MPI. Completes the declaration of this type in civlc-common.h */
|
|---|
| 27 | struct __gcomm__ {
|
|---|
| 28 | int nprocs; // number of processes
|
|---|
| 29 | _Bool isInit[]; // if the local comm has been initiated
|
|---|
| 30 | $queue buf[][]; // message buffers
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | /* A datatype representing a local communicator which is used for
|
|---|
| 34 | * operating global communicators. The local communicator type has
|
|---|
| 35 | * a handle of a global communicator. This type represents for
|
|---|
| 36 | * a set of processes which have ranks in common.
|
|---|
| 37 | * Completes the declaration of this type in civlc-common.h.
|
|---|
| 38 | */
|
|---|
| 39 | struct __comm__ {
|
|---|
| 40 | int place;
|
|---|
| 41 | $gcomm gcomm;
|
|---|
| 42 | };
|
|---|
| 43 |
|
|---|
| 44 | /* *********************** Functions *********************** */
|
|---|
| 45 |
|
|---|
| 46 | /* creates a new message, copying data from the specified buffer */
|
|---|
| 47 | $message $message_pack(int source, int dest, int tag,
|
|---|
| 48 | void *data, int size) {
|
|---|
| 49 | $message result;
|
|---|
| 50 |
|
|---|
| 51 | result.source = source;
|
|---|
| 52 | result.dest = dest;
|
|---|
| 53 | result.tag = tag;
|
|---|
| 54 | result.data = $bundle_pack(data, size);
|
|---|
| 55 | result.size = size;
|
|---|
| 56 | return result;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /* returns the message source */
|
|---|
| 60 | int $message_source($message message) {
|
|---|
| 61 | return message.source;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /* returns the message tag */
|
|---|
| 65 | int $message_tag($message message) {
|
|---|
| 66 | return message.tag;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | /* returns the message destination */
|
|---|
| 70 | int $message_dest($message message) {
|
|---|
| 71 | return message.dest;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /* returns the message size */
|
|---|
| 75 | int $message_size($message message) {
|
|---|
| 76 | return message.size;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /* transfers message data to buf, throwing exception if message
|
|---|
| 80 | * size exceeds specified size */
|
|---|
| 81 | void $message_unpack($message message, void *buf, int size) {
|
|---|
| 82 | $bundle_unpack(message.data, buf);
|
|---|
| 83 | $assert((message.size <= size,
|
|---|
| 84 | "Message of size %d exceeds the specified size %d.", message.size, size));
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /* Returns the place of the local communicator. This is the same as the
|
|---|
| 88 | * place argument used to create the local communicator. */
|
|---|
| 89 | int $comm_place($comm comm){
|
|---|
| 90 | return comm->place;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | #endif
|
|---|