source: CIVL/text/include/comm.cvl@ ca5efc4

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

Added separated libraries for civl (including civl implementation and library enabler/evaluator/executor); modified the examples in example/library/civlc accordingly;

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

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