NAMD
Public Member Functions | List of all members
GlobalMasterServer Class Reference

#include <GlobalMasterServer.h>

Public Member Functions

 GlobalMasterServer (ComputeMgr *m, int theNumDataSenders)
 
virtual ~GlobalMasterServer ()
 
void recvData (ComputeGlobalDataMsg *)
 
void addClient (GlobalMaster *newClient)
 

Detailed Description

Definition at line 22 of file GlobalMasterServer.h.

Constructor & Destructor Documentation

◆ GlobalMasterServer()

GlobalMasterServer::GlobalMasterServer ( ComputeMgr m,
int  theNumDataSenders 
)

Definition at line 579 of file GlobalMasterServer.C.

References DebugM, SimParameters::globalMasterFrequency, SimParameters::lattice, Node::Object(), and Node::simParameters.

580  {
581  DebugM(3,"Constructing GlobalMasterServer\n");
582  myComputeManager = m;
583  numDataSenders = 0; // theNumDataSenders;
584  numForceSenders = 0;
585  latticeCount = 0;
586  lattice = Node::Object()->simParameters->lattice;
588  recvCount = 0; /* we haven't gotten any messages yet */
589  recvPatchesCount = 0;
590  firstTime = 1; /* XXX temporary */
591  step = -1;
592  totalAtomsRequested = 0;
593  totalGroupsRequested = 0;
594  forceSendEnabled = 0;
595  if ( Node::Object()->simParameters->tclForcesOn ) forceSendEnabled = 1;
596  if ( Node::Object()->simParameters->colvarsOn ) forceSendEnabled = 1;
597  DebugM(3,"done constructing\n");
598 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
#define DebugM(x, y)
Definition: Debug.h:75
int globalMasterFrequency

◆ ~GlobalMasterServer()

GlobalMasterServer::~GlobalMasterServer ( )
virtual

Definition at line 600 of file GlobalMasterServer.C.

600  {
601  GlobalMaster *m_i = *clientList.begin();
602  GlobalMaster *m_e = *clientList.end();
603 
604  /* delete each of the masters */
605  while(m_i != m_e) {
606  delete m_i;
607  m_i++;
608  }
609 }
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37

Member Function Documentation

◆ addClient()

void GlobalMasterServer::addClient ( GlobalMaster newClient)

Definition at line 33 of file GlobalMasterServer.C.

References DebugM, and GlobalMaster::setLattice().

Referenced by ComputeMgr::createComputes().

33  {
34  DebugM(3,"Adding client\n");
35  clientList.add(newClient);
36  newClient->setLattice(&lattice);
37  DebugM(2,"Added.\n");
38 }
#define DebugM(x, y)
Definition: Debug.h:75
int add(const Elem &elem)
Definition: ResizeArray.h:101
void setLattice(const Lattice *lat)
Definition: GlobalMaster.h:78

◆ recvData()

void GlobalMasterServer::recvData ( ComputeGlobalDataMsg msg)

Definition at line 40 of file GlobalMasterServer.C.

References ComputeGlobalDataMsg::aid, ResizeArray< Elem >::begin(), ComputeGlobalDataMsg::count, DebugM, ResizeArray< Elem >::end(), endi(), ComputeGlobalDataMsg::fid, ComputeGlobalDataMsg::gcom, ComputeGlobalDataMsg::gmass, ComputeGlobalDataMsg::gridobjindex, ComputeGlobalDataMsg::gridobjvalue, ComputeGlobalDataMsg::gtf, ComputeGlobalDataMsg::lat, NAMD_bug(), PatchMap::numPatches(), PatchMap::Object(), ComputeGlobalDataMsg::p, ComputeGlobalDataMsg::patchcount, ResizeArray< Elem >::size(), ComputeGlobalDataMsg::step, and ComputeGlobalDataMsg::tf.

Referenced by ComputeMgr::recvComputeGlobalData().

40  {
41  DebugM(3,"Storing data (" << msg->aid.size() << " positions) on master\n");
42 
43  if ( msg->step != -1 ) step = msg->step;
44 
45  /* get the beginning and end of the lists */
46  AtomIDList::iterator a_i = msg->aid.begin();
47  AtomIDList::iterator a_e = msg->aid.end();
48  PositionList::iterator p_i = msg->p.begin();
49  PositionList::iterator g_i = msg->gcom.begin();
50  PositionList::iterator g_e = msg->gcom.end();
51  BigRealList::iterator gm_i = msg->gmass.begin();
52 
53  /* iterate over each member of the atom lists */
54  for ( ; a_i != a_e; ++a_i, ++p_i ) {
55  receivedAtomIDs.add(*a_i);
56  receivedAtomPositions.add(*p_i);
57  }
58 
59  /* iterate over each member of "total force" lists */
60  a_e = msg->fid.end();
61  ForceList::iterator f_i=msg->tf.begin();
62  for (a_i=msg->fid.begin() ; a_i!=a_e; ++a_i,++f_i) {
63  receivedForceIDs.add(*a_i);
64  receivedTotalForces.add(*f_i);
65  }
66 
67  /* iterate over each member of the group position list */
68  int i=0;
69  for ( ; g_i != g_e; ++g_i, ++gm_i ) {
70  DebugM(1,"Received center of mass "<<*g_i<<"\n");
71  if(i >= totalGroupsRequested) NAMD_bug("Received too many groups.");
72  receivedGroupPositions[i] += (*g_i);
73  receivedGroupMasses[i] += (*gm_i);
74  i++;
75  }
76  if(i!=totalGroupsRequested) NAMD_bug("Received too few groups.");
77 
78  /* iterate over each member of group total force lists */
79  int ntf = msg->gtf.size();
80  if ( ntf && ntf != receivedGroupTotalForces.size() ) NAMD_bug("Received wrong number of group forces.");
81  ForceList::iterator gf_i=msg->gtf.begin();
82  ForceList::iterator gf_e=msg->gtf.end();
83  for ( i=0 ; gf_i != gf_e; ++gf_i, ++i ) {
84  receivedGroupTotalForces[i] += (*gf_i);
85  }
86 
87  // Get values of the GridForce objects
88  int ngov = msg->gridobjvalue.size();
89  IntList::iterator goi_i = msg->gridobjindex.begin();
91  BigRealList::iterator gov_e = msg->gridobjvalue.end();
92  for ( i=0 ; gov_i != gov_e; gov_i++, goi_i++, i++ ) {
93  receivedGridObjIndices[i] = (*goi_i);
94  receivedGridObjValues[i] += (*gov_i);
95  }
96  if (ngov && ngov != receivedGridObjValues.size()) {
97  NAMD_bug("Received wrong number of grid objects.");
98  }
99 
100  if ( msg->lat.size() ) {
101  if ( latticeCount ) {
102  NAMD_bug("GlobalMasterServer::recvData received lattice twice.");
103  }
104  lattice = msg->lat[0];
105  latticeCount = 1;
106  }
107 
108  recvCount += msg->count;
109  recvPatchesCount += msg->patchcount;
110  int numPatches = PatchMap::Object()->numPatches();
111 
112  /* done with the message, delete it */
113  delete msg;
114 
115  /* check whether we've gotten all the expected messages */
116 
117  DebugM(3, "received " << recvCount << " atom messages and "
118  << recvPatchesCount << " patch messages (out of " << numPatches
119  << " patches) from the ComputeGlobals\n" << endi);
120 
121  int numNeededPatches = totalGridObjsRequested ? numPatches : 0;
122  if (firstTime) numNeededPatches = 0;
123 
124  if (recvCount > numDataSenders + numForceSenders + 1) {
125  NAMD_bug("GlobalMasterServer::recvData recvCount too high.");
126  }
127  if(recvCount == numDataSenders + numForceSenders + 1) {
128  if ( ! latticeCount ) {
129  NAMD_bug("GlobalMasterServer::recvData did not receive lattice.");
130  }
131 
132  DebugM(3, "Received all needed data\n" << endi);
133 
134 #ifdef DEBUGM
135  for (size_t ig = 0; ig < receivedGroupMasses.size(); ig++) {
136  // The groups' positions will be normalized later, in callClients()
137  DebugM(3, "Group mass " << ig << " = "
138  << receivedGroupMasses[ig] << "\n" << endi);
139  }
140  for (size_t ig = 0; ig < receivedGridObjValues.size(); ig++) {
141  DebugM(3, "Grid object " << receivedGridObjIndices[ig] << " = "
142  << receivedGridObjValues[ig] << "\n" << endi);
143  }
144 #endif
145 
146  int oldTotalGroupsRequested = totalGroupsRequested;
147 
148  DebugM(3,"received messages from each of the ComputeGlobals\n");
149  int resendCoordinates = callClients();
150 
151  if (resendCoordinates) {
152  DebugM(3, "resendCoordinates\n" << endi);
153  }
154 
155  /* now restart */
156  step = -1;
157  receivedAtomIDs.resize(0);
158  receivedAtomPositions.resize(0);
159  receivedGroupPositions.resize(totalGroupsRequested);
160  receivedGroupPositions.setall(Vector(0,0,0));
161  receivedGroupMasses.resize(totalGroupsRequested);
162  receivedGroupMasses.setall(0);
163  receivedGridObjIndices.resize(totalGridObjsRequested);
164  receivedGridObjIndices.setall(-1);
165  receivedGridObjValues.resize(totalGridObjsRequested);
166  receivedGridObjValues.setall(0);
167  latticeCount = 0;
168  recvCount = 0;
169  recvPatchesCount = 0;
170  if ( resendCoordinates ) {
171  recvCount += numForceSenders;
172  } else {
173  receivedGroupTotalForces.resize(totalGroupsRequested);
174  receivedGroupTotalForces.setall(0);
175  receivedForceIDs.resize(0);
176  receivedTotalForces.resize(0);
177  }
178  }
179 }
int size(void) const
Definition: ResizeArray.h:131
static PatchMap * Object()
Definition: PatchMap.h:27
BigRealList gridobjvalue
Partial values of the GridForce objects from this message.
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
int add(const Elem &elem)
Definition: ResizeArray.h:101
void resize(int i)
Definition: ResizeArray.h:84
void setall(const Elem &elem)
Definition: ResizeArray.h:94
int numPatches(void) const
Definition: PatchMap.h:59
void NAMD_bug(const char *err_msg)
Definition: common.C:195
ResizeArray< Lattice > lat
IntList gridobjindex
Indices of the GridForce objects contained in this message.
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
int count
Numer of atoms processed for this message.
int patchcount
Number of patches processed for this message.

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