#include /* This file completes the definitions of some types and functions * for communication, which are declared in comm-common.cvh. */ #ifdef __CIVLC_COMM__ #else #define __CIVLC_COMM__ #include /* *********************** Types *********************** */ /* A datatype representing a queue of messages. All message * data is encapsulated inside this value; no external allocation * is used. Completes the declaration of this structure type in * civlc-common.h */ struct __queue__ { int length; $message messages[]; }; /* A global communicator datatype which must be operated by local communicators. * This communicator type has the same meaning as the communicator type * in MPI. Completes the declaration of this type in civlc-common.h */ struct __gcomm__ { int nprocs; // number of processes _Bool isInit[]; // if the local comm has been initiated $queue buf[][]; // message buffers }; /* A datatype representing a local communicator which is used for * operating global communicators. The local communicator type has * a handle of a global communicator. This type represents for * a set of processes which have ranks in common. * Completes the declaration of this type in civlc-common.h. */ struct __comm__ { int place; $gcomm gcomm; }; /* *********************** Functions *********************** */ /* creates a new message, copying data from the specified buffer */ $message $message_pack(int source, int dest, int tag, void *data, int size) { $message result; result.source = source; result.dest = dest; result.tag = tag; result.data = $bundle_pack(data, size); result.size = size; return result; } /* returns the message source */ int $message_source($message message) { return message.source; } /* returns the message tag */ int $message_tag($message message) { return message.tag; } /* returns the message destination */ int $message_dest($message message) { return message.dest; } /* returns the message size */ int $message_size($message message) { return message.size; } /* transfers message data to buf, throwing exception if message * size exceeds specified size */ void $message_unpack($message message, void *buf, int size) { $bundle_unpack(message.data, buf); $assert((message.size <= size, "Message of size %d exceeds the specified size %d.", message.size, size)); } /* Returns the place of the local communicator. This is the same as the * place argument used to create the local communicator. */ int $comm_place($comm comm){ return comm->place; } #endif