NAMD
Public Member Functions | Static Public Member Functions | List of all members
BroadcastMgr Class Reference

#include <BroadcastMgr.h>

Inheritance diagram for BroadcastMgr:

Public Member Functions

 BroadcastMgr ()
 
 ~BroadcastMgr (void)
 
int getbuf (BroadcastClient &b, int tag, void *msg)
 
void send (BroadcastClient &b, int tag, void *buf, size_t)
 
void subscribe (BroadcastClient &bc)
 
void unsubscribe (BroadcastClient &bc)
 
void recvBroadcast (BroadcastMsg *msg)
 

Static Public Member Functions

static BroadcastMgrObject ()
 

Detailed Description

Definition at line 87 of file BroadcastMgr.h.

Constructor & Destructor Documentation

BroadcastMgr::BroadcastMgr ( )
inline

Definition at line 90 of file BroadcastMgr.h.

90  {
91  CkpvAccess(BroadcastMgr_instance) = this;
92  }
BroadcastMgr::~BroadcastMgr ( void  )

Definition at line 18 of file BroadcastMgr.C.

References UniqueSetIter< Type >::begin(), and UniqueSetIter< Type >::end().

18  {
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 }

Member Function Documentation

int BroadcastMgr::getbuf ( BroadcastClient b,
int  tag,
void msg 
)

Definition at line 30 of file BroadcastMgr.C.

References TaggedMsg::counter, UniqueSet< Elem >::find(), BroadcastClient::id, TaggedMsg::msg, TaggedMsg::msgSize, and BOID::taggedMsg.

30  {
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 }
Elem * find(const Elem &elem)
Definition: UniqueSet.h:60
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
char msg[BCASTMSGSIZE]
Definition: BroadcastMgr.h:67
static BroadcastMgr* BroadcastMgr::Object ( )
inlinestatic

Definition at line 96 of file BroadcastMgr.h.

Referenced by BroadcastClient::BroadcastClient(), SimpleBroadcastObject< Tensor >::get(), SimpleBroadcastObject< Tensor >::publish(), and BroadcastClient::~BroadcastClient().

96  {
97  return CkpvAccess(BroadcastMgr_instance);
98  }
void BroadcastMgr::recvBroadcast ( BroadcastMsg msg)

Definition at line 86 of file BroadcastMgr.C.

References UniqueSet< Elem >::add(), UniqueSetIter< Type >::begin(), BOID::broadcastSet, UniqueSetIter< Type >::end(), UniqueSet< Elem >::find(), NAMD_bug(), UniqueSet< Elem >::size(), and BOID::taggedMsg.

86  {
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 }
Elem * find(const Elem &elem)
Definition: UniqueSet.h:60
int add(const Elem &elem)
Definition: UniqueSet.h:52
int size(void) const
Definition: UniqueSet.h:58
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
void NAMD_bug(const char *err_msg)
Definition: common.C:123
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:83
void BroadcastMgr::send ( BroadcastClient b,
int  tag,
void buf,
size_t  size 
)

Definition at line 49 of file BroadcastMgr.C.

References BroadcastClient::id.

Referenced by SimpleBroadcastObject< Tensor >::publish().

49  {
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 }
void BroadcastMgr::subscribe ( BroadcastClient bc)

Definition at line 60 of file BroadcastMgr.C.

References UniqueSet< Elem >::add(), BOID::broadcastSet, UniqueSet< Elem >::find(), BroadcastClient::id, and BOID::taggedMsg.

Referenced by BroadcastClient::BroadcastClient().

60  {
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 }
Elem * find(const Elem &elem)
Definition: UniqueSet.h:60
int add(const Elem &elem)
Definition: UniqueSet.h:52
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:83
void BroadcastMgr::unsubscribe ( BroadcastClient bc)

Definition at line 72 of file BroadcastMgr.C.

References BOID::broadcastSet, UniqueSet< Elem >::del(), UniqueSet< Elem >::find(), BroadcastClient::id, UniqueSet< Elem >::size(), and BOID::taggedMsg.

Referenced by BroadcastClient::~BroadcastClient().

72  {
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 }
Elem * find(const Elem &elem)
Definition: UniqueSet.h:60
int size(void) const
Definition: UniqueSet.h:58
UniqueSet< TaggedMsg > * taggedMsg
Definition: BroadcastMgr.h:84
UniqueSet< BroadcastClientElem > * broadcastSet
Definition: BroadcastMgr.h:83
int del(const Elem &elem)
Definition: UniqueSet.h:56

The documentation for this class was generated from the following files: