source: CIVL/text/include/comm.cvl@ 7d23067

1.23 2.0 main test-branch
Last change on this file since 7d23067 was 7168bfa, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added $assert statement and implemented its semantics; updated examples/libraries according to the new syntax of $assert.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1452 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#ifdef __CIVLC_COMM__
6#else
7#define __CIVLC_COMM__
8
9#include<comm.cvh>
10
11/* *********************** Types *********************** */
12
13/* A datatype representing a queue of messages. All message
14 * data is encapsulated inside this value; no external allocation
15 * is used. Completes the declaration of this structure type in
16 * civlc-common.h */
17struct __queue__ {
18 int length;
19 $message messages[];
20};
21
22
23/* A global communicator datatype which must be operated by local communicators.
24 * This communicator type has the same meaning as the communicator type
25 * in MPI. Completes the declaration of this type in civlc-common.h */
26struct __gcomm__ {
27 int nprocs; // number of processes
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 :
83 "Message of size %d exceeds the specified size %d.", message.size, size;
84}
85
86/* Returns the place of the local communicator. This is the same as the
87 * place argument used to create the local communicator. */
88int $comm_place($comm comm){
89 return comm->place;
90}
91
92#endif
Note: See TracBrowser for help on using the repository browser.