NAMD
Public Member Functions | Public Attributes | List of all members
SimpleBroadcastObject< T > Class Template Reference

#include <BroadcastObject.h>

Inheritance diagram for SimpleBroadcastObject< T >:
BroadcastClient

Public Member Functions

 SimpleBroadcastObject (int id_in, const LDObjHandle *h=0, NodeBroadcast *nodeBroadcastIn=0, const bool useSharedIfPossible=false)
 Creates a new SimpleBroadcastObject with given id. More...
 
 ~SimpleBroadcastObject ()
 
get (int tag, const int expected=-1)
 Attempts to retrieve a previously published value for a given tag and id. More...
 
int getSize ()
 
int getBcastSize ()
 
int getTaggedSize ()
 
void publish (int tag, const T &t)
 
- Public Member Functions inherited from BroadcastClient
 BroadcastClient (int id)
 
 ~BroadcastClient ()
 
void awaken (int id, int tag)
 

Public Attributes

const LDObjHandle * ldObjPtr
 
bool useShared = false
 
int id = -1
 
NodeBroadcastnodeBroadcast
 
- Public Attributes inherited from BroadcastClient
int id
 

Additional Inherited Members

- Protected Member Functions inherited from BroadcastClient
void suspendFor (int tag)
 
- Protected Attributes inherited from BroadcastClient
int suspended
 
int waitForTag
 
CthThread thread
 

Detailed Description

template<class T>
class SimpleBroadcastObject< T >

Definition at line 53 of file BroadcastObject.h.

Constructor & Destructor Documentation

◆ SimpleBroadcastObject()

template<class T>
SimpleBroadcastObject< T >::SimpleBroadcastObject ( int  id_in,
const LDObjHandle *  h = 0,
NodeBroadcast nodeBroadcastIn = 0,
const bool  useSharedIfPossible = false 
)
inline

Creates a new SimpleBroadcastObject with given id.

NodeBroadcast is used by the shared memory backend and the same pointer should be given to all objects on all Pes.

Even if we are using the shared memory backend, some of the broadcast objects must still use the charm++ backend since they are used for barriers, like scriptBarrier. The shared memory backend must be explicitly enabled using the useSharedIfPossible parameter

Definition at line 74 of file BroadcastObject.h.

76  : BroadcastClient(id_in), ldObjPtr(h), nodeBroadcast(nodeBroadcastIn), id(id_in) {
77  if ( sizeof(T) > BCASTMSGSIZE ) {
78  NAMD_bug("SimpleBroadcastObject instantiated on class larger than BCASTMSGSIZE");
79  }
80 
81  if (nodeBroadcast != 0) {
83 
84  if (useShared) {
85  // Add a map for this broadcast object if needed
86  CmiLock(nodeBroadcast->lock);
87  if (nodeBroadcast->data.find(id) == nodeBroadcast->data.end()) {
88  nodeBroadcast->data[id] = new std::map<int, T>();
89  }
90  CmiUnlock(nodeBroadcast->lock);
91  }
92  }
93  }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
const LDObjHandle * ldObjPtr
void NAMD_bug(const char *err_msg)
Definition: common.C:196
std::map< int, std::any > data
NodeBroadcast * nodeBroadcast
Bool GPUresidentSingleProcessMode
#define BCASTMSGSIZE
Definition: BroadcastMgr.h:22
BroadcastClient(int id)
CmiNodeLock lock

◆ ~SimpleBroadcastObject()

template<class T>
SimpleBroadcastObject< T >::~SimpleBroadcastObject ( )
inline

Definition at line 94 of file BroadcastObject.h.

94 { }

Member Function Documentation

◆ get()

template<class T>
T SimpleBroadcastObject< T >::get ( int  tag,
const int  expected = -1 
)
inline

Attempts to retrieve a previously published value for a given tag and id.

This function has slightly different behavior between the shared memory and charm++ backends. The Charm++ backend will suspend and wait if it attempts to retrieve an unpublished tag, while the shared memory backend will throw an error. The shared memory backend also should be given the expected number of retrievals so the data can be removed

Definition at line 105 of file BroadcastObject.h.

Referenced by Sequencer::adaptTempUpdate(), Sequencer::algorithm(), Controller::algorithm(), Sequencer::berendsenPressure(), Sequencer::berendsenPressure_SOA(), Sequencer::correctMomentum(), Sequencer::langevinPiston(), Sequencer::langevinPiston_SOA(), Sequencer::minimize(), Sequencer::multigratorPressure(), Sequencer::multigratorTemperature(), Sequencer::rescaleaccelMD(), Sequencer::rescaleVelocities(), Sequencer::stochRescaleVelocities(), Sequencer::stochRescaleVelocities_SOA(), Sequencer::submitCollections(), Sequencer::tcoupleVelocities(), and Sequencer::traceBarrier().

105  {
106  T tmp;
107  if (useShared) {
108  CmiLock(nodeBroadcast->lock);
109  // Attempt to retrieve data from map
110  if (nodeBroadcast->data.find(id) == nodeBroadcast->data.end()) {
111  NAMD_bug("SimpleBroadcastObject: Did not find id");
112  }
113  std::map<int, T>* data = std::any_cast<std::map<int, T>*>(nodeBroadcast->data[id]);
114  if (data->find(tag) == data->end()) {
115  NAMD_bug("SimpleBroadcastObject: Did not find tag");
116  }
117  tmp = (*data)[tag];
118  // Check if the data has been retrieved the expected number of times, if so, delete it.
119  nodeBroadcast->current[id][tag]++;
120  if (nodeBroadcast->current[id][tag] == expected) {
121  data->erase(tag);
122  nodeBroadcast->current[id].erase(tag);
123  }
124  CmiUnlock(nodeBroadcast->lock);
125  } else {
127  while ( BroadcastMgr::Object()->getbuf(*this, tag, (void*)(&tmp)) < 0 ) {
128  suspendFor(tag);
129  }
131  }
132  return tmp;
133  }
void startWork(const LDObjHandle &handle)
void pauseWork(const LDObjHandle &handle)
const LDObjHandle * ldObjPtr
void NAMD_bug(const char *err_msg)
Definition: common.C:196
std::map< int, std::any > data
NodeBroadcast * nodeBroadcast
static LdbCoordinator * Object()
void suspendFor(int tag)
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95
CmiNodeLock lock
std::map< int, std::map< int, int > > current

◆ getBcastSize()

template<class T>
int SimpleBroadcastObject< T >::getBcastSize ( )
inline

Definition at line 137 of file BroadcastObject.h.

137  {
139  }
int boidBroadcastSize()
Definition: BroadcastMgr.C:28
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95

◆ getSize()

template<class T>
int SimpleBroadcastObject< T >::getSize ( )
inline

Definition at line 134 of file BroadcastObject.h.

134  {
135  return BroadcastMgr::Object()->boidSize();
136  }
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95

◆ getTaggedSize()

template<class T>
int SimpleBroadcastObject< T >::getTaggedSize ( )
inline

Definition at line 140 of file BroadcastObject.h.

140  {
142  }
int boidTaggedMsgSize()
Definition: BroadcastMgr.C:38
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95

◆ publish()

template<class T>
void SimpleBroadcastObject< T >::publish ( int  tag,
const T &  t 
)
inline

Definition at line 143 of file BroadcastObject.h.

Referenced by Controller::adaptTempUpdate(), Controller::berendsenPressure(), Controller::correctMomentum(), Controller::langevinPiston1(), Controller::minimize(), Controller::monteCarloPressure_accept(), Controller::monteCarloPressure_prepare(), Controller::multigratorPressure(), Controller::multigratorTemperature(), Controller::printEnergies(), Controller::rescaleaccelMD(), Controller::rescaleVelocities(), Controller::resumeAfterTraceBarrier(), Controller::stochRescaleVelocities(), and Controller::tcoupleVelocities().

143  {
144  if (useShared) {
145  CmiLock(nodeBroadcast->lock);
146  // Insert new data into map.
147  std::map<int, T>* data = std::any_cast<std::map<int, T>*>(nodeBroadcast->data[id]);
148  data->insert({tag, t});
149  // Reset retrieval counter to 0.
150  nodeBroadcast->current[id][tag] = 0;
151  CmiUnlock(nodeBroadcast->lock);
152  } else {
153  BroadcastMgr::Object()->send(*this, tag, (void*)(&t), sizeof(T));
154  }
155  }
void send(BroadcastClient &b, int tag, void *buf, size_t)
Definition: BroadcastMgr.C:69
std::map< int, std::any > data
NodeBroadcast * nodeBroadcast
static BroadcastMgr * Object()
Definition: BroadcastMgr.h:95
CmiNodeLock lock
std::map< int, std::map< int, int > > current

Member Data Documentation

◆ id

template<class T>
int SimpleBroadcastObject< T >::id = -1

◆ ldObjPtr

template<class T>
const LDObjHandle* SimpleBroadcastObject< T >::ldObjPtr

Definition at line 57 of file BroadcastObject.h.

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

◆ nodeBroadcast

template<class T>
NodeBroadcast* SimpleBroadcastObject< T >::nodeBroadcast

◆ useShared

template<class T>
bool SimpleBroadcastObject< T >::useShared = false

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