NAMD
BroadcastMgr.C
Go to the documentation of this file.
1 
7 #include "UniqueSet.h"
8 #include "UniqueSetIter.h"
9 #include "BroadcastMgr.decl.h"
10 #include "BroadcastMgr.h"
11 #include "BroadcastClient.h"
12 #include "BroadcastObject.h"
13 #include "ProcessorPrivate.h"
14 #define MIN_DEBUG_LEVEL 3
15 //#define DEBUGM
16 #include "Debug.h"
17 
19  UniqueSetIter<BOID> boidIter(boid);
20  for (boidIter = boidIter.begin(); boidIter != boidIter.end(); boidIter++) {
21  delete boidIter->broadcastSet;
22  if (boidIter->taggedMsg) {
23  delete boidIter->taggedMsg;
24  }
25  }
26 }
27 
28 
29 int
30 BroadcastMgr::getbuf(BroadcastClient &b, int tag, void *msg) {
31  int rval = -1;
32  TaggedMsg *tm;
33  BOID* boidTmp = boid.find(BOID(b.id));
34  if (!boidTmp) {
35  return(-2);
36  }
37  if ( (tm = (boidTmp->taggedMsg->find(TaggedMsg(tag)))) ) {
38  rval = tm->msgSize;
39  memcpy(msg, tm->msg, tm->msgSize);
40  if (!--(tm->counter)) {
41  (boid.find(BOID(b.id)))->taggedMsg->del(TaggedMsg(tag));
42  }
43  }
44  return(rval);
45 }
46 
47 
48 void
49 BroadcastMgr::send(BroadcastClient &b, int tag, void *buf, size_t size) {
50  BroadcastMsg* msg = new BroadcastMsg;
51  memcpy((void*)(msg->msg),buf,size);
52  msg->size = (int)size;
53  msg->tag = tag;
54  msg->id = b.id;
55  msg->node = CkMyPe();
56  CProxy_BroadcastMgr(thisgroup).recvBroadcast(msg);
57 }
58 
59 void
61  BOID *b;
62  if (!(b = boid.find(BOID(bc.id)))) {
63  boid.add(BOID(bc.id));
64  b = boid.find(BOID(bc.id));
67  }
69 }
70 
71 void
73  BOID *b;
74  if ( (b = boid.find(BOID(bc.id))) ) {
76  if (!b->broadcastSet->size()) {
77  delete b->broadcastSet;
78  b->broadcastSet = 0;
79  delete b->taggedMsg;
80  b->taggedMsg = 0;
81  }
82  }
83 }
84 
85 void
87  BOID *b;
88  int counter;
89  // Check if msg->id has any registrants
90  if ( (b = boid.find(BOID(msg->id))) ) {
91  // add message to taggedMsg container
92  counter = b->broadcastSet->size();
93  if (msg->node == CkMyPe()) counter--; // get rid of sender
94  if ( counter < 0 ) NAMD_bug("BroadcastMgr::recvBroadcast counter < 0");
95  else if ( counter > 0 ) {
96  b->taggedMsg->add(TaggedMsg(msg->tag,msg->size,counter,msg->msg));
97 
98  // inform all registrants of mew message
100  for (bcIter = bcIter.begin(); bcIter != bcIter.end(); bcIter++) {
101  bcIter->broadcastClient->awaken(msg->id, msg->tag);
102  }
103  }
104  }
105  delete msg;
106 }
107 
108 #include "BroadcastMgr.def.h"
109 
Elem * find(const Elem &elem)
Definition: UniqueSet.h:60
void recvBroadcast(BroadcastMsg *msg)
Definition: BroadcastMgr.C:86
int add(const Elem &elem)
Definition: UniqueSet.h:52
int size(void) const
Definition: UniqueSet.h:58
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
int getbuf(BroadcastClient &b, int tag, void *msg)
Definition: BroadcastMgr.C:30
char msg[BCASTMSGSIZE]
Definition: BroadcastMgr.h:67
void unsubscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:72
UniqueSetIter< T > begin(void) const
Definition: UniqueSetIter.h:55
void send(BroadcastClient &b, int tag, void *buf, size_t)
Definition: BroadcastMgr.C:49
void NAMD_bug(const char *err_msg)
Definition: common.C:123
~BroadcastMgr(void)
Definition: BroadcastMgr.C:18
void subscribe(BroadcastClient &bc)
Definition: BroadcastMgr.C:60
UniqueSetIter< T > end(void) const
Definition: UniqueSetIter.h:64
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:83
int del(const Elem &elem)
Definition: UniqueSet.h:56