source: CIVL/src/include/civl/comm.cvl@ 49baa33

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 49baa33 was bf584ca, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

cleaned up #ifdef ... #else of headers using #ifndef.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2292 fb995dde-84ed-4084-dfe6-e5aef3e2452c

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