NAMD
BroadcastMgr.h
Go to the documentation of this file.
1 
7 /*
8  Coordinates broadcast of a data type from a Controller/Seq
9  to all other Controller/Sequencer type objects (they must
10  run in a thread!)
11 */
12 
13 #include "charm++.h"
14 #include "main.h"
15 #include "UniqueSet.h"
16 #include "UniqueSetIter.h"
17 #include "ProcessorPrivate.h"
18 #include "BroadcastMgr.decl.h"
19 
20 #ifndef _BCASTMGR_H
21 #define _BCASTMGR_H
22 
23 #define BCASTMSGSIZE (9*sizeof(double))
24 
25 class BroadcastMsg : public CMessage_BroadcastMsg {
26 friend class BroadcastMgr;
27 public:
30 
31 private:
32  // Only seen by BroadcastMgr
33  char msg[BCASTMSGSIZE];
34  int size;
35  int id;
36  int tag;
37  int node;
38 };
39 
40 class BroadcastClient;
41 
43 public:
47 
49 
50  size_t hash() const { return (size_t)broadcastClient; }
51  int operator==(const BroadcastClientElem &b) const {
52  return broadcastClient == b.broadcastClient;
53  }
54 };
55 
56 class TaggedMsg {
57 public:
58  TaggedMsg() {}
59  TaggedMsg(int t) : tag(t) {}
60  TaggedMsg(int t, int s, int c, void *m)
61  : tag(t), counter(c), msgSize(s) { memcpy((void*)msg,m,s); }
63 
64  int tag;
65  int counter;
66  int msgSize;
68 
69  int hash() const { return tag; }
70  int operator==(const TaggedMsg &tm) const { return(tag == tm.tag); }
71 };
72 
73 class BOID {
74 public:
75  BOID() {}
76  BOID(int id) { this->id = id; }
77  ~BOID() {}
78 
79  int hash() const { return id; }
80  int operator==(const BOID &b) const { return id == b.id; }
81  int id;
82 
85 };
86 
87 class BroadcastMgr : public CBase_BroadcastMgr
88 {
89 public:
91  CkpvAccess(BroadcastMgr_instance) = this;
92  }
93  ~BroadcastMgr(void);
94 
95  // Singleton Access method
96  inline static BroadcastMgr *Object() {
97  return CkpvAccess(BroadcastMgr_instance);
98  }
99 
100  int getbuf(BroadcastClient &b, int tag, void* msg);
101  void send(BroadcastClient &b, int tag, void *buf, size_t);
102  void subscribe(BroadcastClient &bc);
103  void unsubscribe(BroadcastClient &bc);
104  void recvBroadcast(BroadcastMsg *msg);
105 
106 private:
107  UniqueSet<BOID> boid;
108 };
109 
110 #endif /* _BCASTMGR_H */
111 
int operator==(const BOID &b) const
Definition: BroadcastMgr.h:80
int hash() const
Definition: BroadcastMgr.h:79
void recvBroadcast(BroadcastMsg *msg)
Definition: BroadcastMgr.C:86
BroadcastClientElem(BroadcastClient *c)
Definition: BroadcastMgr.h:45
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
int getbuf(BroadcastClient &b, int tag, void *msg)
Definition: BroadcastMgr.C:30
int operator==(const BroadcastClientElem &b) const
Definition: BroadcastMgr.h:51
size_t hash() const
Definition: BroadcastMgr.h:50
BOID(int id)
Definition: BroadcastMgr.h:76
char msg[BCASTMSGSIZE]
Definition: BroadcastMgr.h:67
void unsubscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:72
TaggedMsg(int t)
Definition: BroadcastMgr.h:59
void send(BroadcastClient &b, int tag, void *buf, size_t)
Definition: BroadcastMgr.C:49
~BroadcastMgr(void)
Definition: BroadcastMgr.C:18
void subscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:60
BroadcastClient * broadcastClient
Definition: BroadcastMgr.h:48
TaggedMsg(int t, int s, int c, void *m)
Definition: BroadcastMgr.h:60
BOID()
Definition: BroadcastMgr.h:75
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:83
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:96
#define BCASTMSGSIZE
Definition: BroadcastMgr.h:23
int id
Definition: BroadcastMgr.h:81
~BOID()
Definition: BroadcastMgr.h:77
int hash() const
Definition: BroadcastMgr.h:69
int operator==(const TaggedMsg &tm) const
Definition: BroadcastMgr.h:70