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 #ifndef _BCASTMGR_H
20 #define _BCASTMGR_H
21 
22 #define BCASTMSGSIZE (9*sizeof(double))
23 
24 class BroadcastMsg : public CMessage_BroadcastMsg {
25 friend class BroadcastMgr;
26 public:
29 
30 private:
31  // Only seen by BroadcastMgr
32  char msg[BCASTMSGSIZE];
33  int size;
34  int id;
35  int tag;
36  int node;
37 };
38 
39 class BroadcastClient;
40 
42 public:
46 
48 
49  size_t hash() const { return (size_t)broadcastClient; }
50  int operator==(const BroadcastClientElem &b) const {
51  return broadcastClient == b.broadcastClient;
52  }
53 };
54 
55 class TaggedMsg {
56 public:
57  TaggedMsg() {}
58  TaggedMsg(int t) : tag(t) {}
59  TaggedMsg(int t, int s, int c, void *m)
60  : tag(t), counter(c), msgSize(s) { memcpy((void*)msg,m,s); }
62 
63  int tag;
64  int counter;
65  int msgSize;
67 
68  int hash() const { return tag; }
69  int operator==(const TaggedMsg &tm) const { return(tag == tm.tag); }
70 };
71 
72 class BOID {
73 public:
74  BOID() {}
75  BOID(int id) { this->id = id; }
76  ~BOID() {}
77 
78  int hash() const { return id; }
79  int operator==(const BOID &b) const { return id == b.id; }
80  int id;
81 
84 };
85 
86 class BroadcastMgr : public CBase_BroadcastMgr
87 {
88 public:
90  CkpvAccess(BroadcastMgr_instance) = this;
91  }
92  ~BroadcastMgr(void);
93 
94  // Singleton Access method
95  inline static BroadcastMgr *Object() {
96  return CkpvAccess(BroadcastMgr_instance);
97  }
98 
99  int getbuf(BroadcastClient &b, int tag, void* msg);
100  void send(BroadcastClient &b, int tag, void *buf, size_t);
101  void subscribe(BroadcastClient &bc);
102  void unsubscribe(BroadcastClient &bc);
103  void recvBroadcast(BroadcastMsg *msg);
104  int boidSize(){ return boid.size();}
105  int boidBroadcastSize();
106  int boidTaggedMsgSize();
107 private:
108  UniqueSet<BOID> boid;
109 };
110 
111 #endif /* _BCASTMGR_H */
112 
int hash() const
Definition: BroadcastMgr.h:68
int size(void) const
Definition: UniqueSet.h:58
void recvBroadcast(BroadcastMsg *msg)
Definition: BroadcastMgr.C:106
size_t hash() const
Definition: BroadcastMgr.h:49
BroadcastClientElem(BroadcastClient *c)
Definition: BroadcastMgr.h:44
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:83
int getbuf(BroadcastClient &b, int tag, void *msg)
Definition: BroadcastMgr.C:50
BOID(int id)
Definition: BroadcastMgr.h:75
int boidBroadcastSize()
Definition: BroadcastMgr.C:28
char msg[BCASTMSGSIZE]
Definition: BroadcastMgr.h:66
void unsubscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:92
TaggedMsg(int t)
Definition: BroadcastMgr.h:58
void send(BroadcastClient &b, int tag, void *buf, size_t)
Definition: BroadcastMgr.C:69
int operator==(const BroadcastClientElem &b) const
Definition: BroadcastMgr.h:50
~BroadcastMgr(void)
Definition: BroadcastMgr.C:18
int boidTaggedMsgSize()
Definition: BroadcastMgr.C:38
void subscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:80
BroadcastClient * broadcastClient
Definition: BroadcastMgr.h:47
TaggedMsg(int t, int s, int c, void *m)
Definition: BroadcastMgr.h:59
int operator==(const BOID &b) const
Definition: BroadcastMgr.h:79
int hash() const
Definition: BroadcastMgr.h:78
BOID()
Definition: BroadcastMgr.h:74
int operator==(const TaggedMsg &tm) const
Definition: BroadcastMgr.h:69
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:82
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95
#define BCASTMSGSIZE
Definition: BroadcastMgr.h:22
int id
Definition: BroadcastMgr.h:80
~BOID()
Definition: BroadcastMgr.h:76