20 #define MIN_DEBUG_LEVEL 3 34 DebugM(3,
"Adding client\n");
35 clientList.add(newClient);
41 DebugM(3,
"Storing data (" << msg->
aid.
size() <<
" positions) on master\n");
43 if ( msg->
step != -1 ) step = msg->
step;
54 for ( ; a_i != a_e; ++a_i, ++p_i ) {
55 receivedAtomIDs.add(*a_i);
56 receivedAtomPositions.add(*p_i);
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);
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);
76 if(i!=totalGroupsRequested)
NAMD_bug(
"Received too few groups.");
80 if ( ntf && ntf != receivedGroupTotalForces.size() )
NAMD_bug(
"Received wrong number of group forces.");
83 for ( i=0 ; gf_i != gf_e; ++gf_i, ++i ) {
84 receivedGroupTotalForces[i] += (*gf_i);
92 for ( i=0 ; gov_i != gov_e; gov_i++, goi_i++, i++ ) {
93 receivedGridObjIndices[i] = (*goi_i);
94 receivedGridObjValues[i] += (*gov_i);
96 if (ngov && ngov != receivedGridObjValues.size()) {
97 NAMD_bug(
"Received wrong number of grid objects.");
101 if ( latticeCount ) {
102 NAMD_bug(
"GlobalMasterServer::recvData received lattice twice.");
104 lattice = msg->
lat[0];
108 recvCount += msg->
count;
117 DebugM(3,
"received " << recvCount <<
" atom messages and " 118 << recvPatchesCount <<
" patch messages (out of " << numPatches
119 <<
" patches) from the ComputeGlobals\n" <<
endi);
121 int numNeededPatches = totalGridObjsRequested ? numPatches : 0;
122 if (firstTime) numNeededPatches = 0;
124 if (recvCount > numDataSenders + numForceSenders + 1) {
125 NAMD_bug(
"GlobalMasterServer::recvData recvCount too high.");
127 if(recvCount == numDataSenders + numForceSenders + 1) {
128 if ( ! latticeCount ) {
129 NAMD_bug(
"GlobalMasterServer::recvData did not receive lattice.");
132 DebugM(3,
"Received all needed data\n" <<
endi);
135 for (
size_t ig = 0; ig < receivedGroupMasses.size(); ig++) {
137 DebugM(3,
"Group mass " << ig <<
" = " 138 << receivedGroupMasses[ig] <<
"\n" <<
endi);
140 for (
size_t ig = 0; ig < receivedGridObjValues.size(); ig++) {
141 DebugM(3,
"Grid object " << receivedGridObjIndices[ig] <<
" = " 142 << receivedGridObjValues[ig] <<
"\n" <<
endi);
146 int oldTotalGroupsRequested = totalGroupsRequested;
148 DebugM(3,
"received messages from each of the ComputeGlobals\n");
149 int resendCoordinates = callClients();
151 if (resendCoordinates) {
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);
169 recvPatchesCount = 0;
170 if ( resendCoordinates ) {
171 recvCount += numForceSenders;
173 receivedGroupTotalForces.resize(totalGroupsRequested);
174 receivedGroupTotalForces.setall(0);
175 receivedForceIDs.resize(0);
176 receivedTotalForces.resize(0);
181 void GlobalMasterServer::resetAtomList(
AtomIDList &atomsRequested) {
190 for(i=0;i<(*m_i)->requestedAtoms().size();i++) {
191 atomsRequested.
add((*m_i)->requestedAtoms()[i]);
199 sort(atomsRequested.
begin(), atomsRequested.
end());
201 atomsRequested.
resize( distance(atomsRequested.
begin(), it) );
204 void GlobalMasterServer::resetGroupList(
AtomIDList &groupsRequested,
206 DebugM(3,
"Rebuilding the group list\n");
207 groupsRequested.
resize(0);
223 DebugM(1,
"adding group "<<*numGroups<<
"\n");
224 for(j=0;j<atoms_in_group.
size();j++) {
225 groupsRequested.
add(atoms_in_group[j]);
228 groupsRequested.
add(-1);
236 void GlobalMasterServer::resetForceList(
AtomIDList &atomsForced,
239 DebugM(1,
"Restting forces\n");
243 lastAtomsForced.resize(0);
244 lastForces.resize(0);
254 DebugM(1,
"Adding atom forces\n");
255 for(i=0;i<(*m_i)->forcedAtoms().size();i++) {
256 atomsForced.
add((*m_i)->forcedAtoms()[i]);
257 forces.
add((*m_i)->appliedForces()[i]);
258 lastAtomsForced.add((*m_i)->forcedAtoms()[i]);
259 lastForces.add((*m_i)->appliedForces()[i]);
263 DebugM(1,
"Adding "<<(*m_i)->requestedGroups().size()<<
" group forces\n");
264 for(i=0;i<(*m_i)->groupForces().size();i++) {
265 groupForces.
add((*m_i)->groupForces()[i]);
269 DebugM(1,
"Next master...\n");
272 DebugM(1,
"Done restting forces\n");
275 void GlobalMasterServer::resetGridObjList(
IntList &gridObjsRequested) {
276 gridObjsRequested.
resize(0);
278 for (
GlobalMaster **m_i = clientList.begin(); m_i != clientList.end();
288 sort(gridObjsRequested.
begin(), gridObjsRequested.
end());
290 gridObjsRequested.
resize( distance(gridObjsRequested.
begin(), it) );
291 totalGridObjsRequested = gridObjsRequested.
size();
294 void GlobalMasterServer::resetGridObjForceList(
BigRealList &gridObjForces)
296 gridObjForces.
resize(totalGridObjsRequested);
297 gridObjForces.
setall(0.0);
301 bool have_forces =
false;
325 int GlobalMasterServer::callClients() {
326 DebugM(3,
"Calling clients\n");
327 bool forceSendActive =
false;
331 for ( ; m_i != m_e; ++m_i ) {
332 if ( (*m_i)->changedAtoms() ) firstTime = 1;
333 if ( (*m_i)->changedGroups() ) firstTime = 1;
334 if ( (*m_i)->requestedTotalForces() ) forceSendActive =
true;
346 DebugM(1,
"first time.\n");
348 resetAtomList(msg->
newaid);
350 resetGroupList(msg->
newgdef,&totalGroupsRequested);
356 numDataSenders = totalAtomsRequested;
360 for ( ; g_i != g_e; ++g_i ) {
363 iout <<
iWARN <<
"Atom " << (*g_i+1) <<
" has a near-zero mass, " 364 <<
"but it was requested for center-of-mass calculation.\n" 373 DebugM(3,
"Sending configure ("<<totalAtomsRequested<<
" atoms, " 374 <<totalGroupsRequested<<
" groups, " << totalGridObjsRequested <<
" grids)\n");
375 DebugM(3,
"calling sendComputeGlobalResults(msg) atoms.\n");
376 myComputeManager->sendComputeGlobalResults(msg);
383 if(receivedAtomIDs.size() != totalAtomsRequested) {
384 DebugM(3,
"Requested " << totalAtomsRequested <<
" atoms.\n");
385 NAMD_bug(
"Got the wrong number of atoms");
387 if(receivedGroupPositions.size() != totalGroupsRequested) {
388 DebugM(3,
"Requested " << totalGroupsRequested <<
" groups.\n");
389 DebugM(3,
"Got " << receivedGroupPositions.size() <<
" group positions.\n");
390 NAMD_bug(
"Got the wrong number of groups");
392 if(receivedGroupMasses.size() != totalGroupsRequested) {
393 DebugM(3,
"Requested " << totalGroupsRequested <<
" groups.\n");
394 DebugM(3,
"Got " << receivedGroupMasses.size() <<
" group masses.\n");
395 NAMD_bug(
"Got the wrong number of group masses");
397 if(receivedGridObjValues.size() != totalGridObjsRequested) {
398 DebugM(3,
"Requested " << totalGridObjsRequested <<
" grid objects.\n");
399 DebugM(3,
"Got " << receivedGridObjValues.size() <<
" grid object values.\n");
400 NAMD_bug(
"Got the wrong number of grid object values");
425 for ( ; g_i < g_e; ++g_i, ++gm_i ) { *g_i /= *gm_i; }
426 g_i = receivedGroupPositions.begin();
427 gm_i = receivedGroupMasses.
begin();
430 bool requested_atoms_changed=
false;
431 bool requested_forces_changed=
false;
432 bool requested_groups_changed=
false;
433 bool requested_grids_changed=
false;
434 forceSendActive =
false;
436 vector <position_index> positions;
437 for (
int j = 0; a_i != a_e; ++a_i, ++j) {
441 positions.push_back(temp);
443 sort(positions.begin(), positions.end(),
atomID_less());
447 int num_atoms_requested, num_groups_requested, num_gridobjs_requested;
460 if (num_atoms_requested) {
461 vector <int> rqAtoms;
465 sort(rqAtoms.begin(), rqAtoms.end());
467 for (
int i = 0; i < positions.size(); i++){
468 if (positions[i].atomID == rqAtoms[j]){
469 clientAtomPositions.
add(receivedAtomPositions[positions[i].index]);
470 clientAtomIDs.
add(rqAtoms[j]);
472 if ( ++j == num_atoms_requested )
break;
475 if ( j != num_atoms_requested )
NAMD_bug(
476 "GlobalMasterServer::callClients() did not find all requested atoms");
496 mp_i,g_i,g_i+num_groups_requested,
497 gm_i,gm_i+num_groups_requested,
499 goi_i, goi_e, gov_i, gov_e,
500 forced_atoms_i,forced_atoms_e,forces_i,
501 receivedForceIDs.begin(),receivedForceIDs.end(),receivedTotalForces.begin());
503 a_i = receivedAtomIDs.begin();
504 p_i = receivedAtomPositions.begin();
509 requested_atoms_changed =
true;
512 requested_forces_changed =
true;
515 requested_groups_changed =
true;
518 requested_grids_changed =
true;
526 g_i += num_groups_requested;
527 gm_i += num_groups_requested;
532 if ( numForceSenders && gtf_i != gtf_e )
NAMD_bug(
"GlobalMasterServer::callClients bad group total force count");
538 if(requested_atoms_changed || requested_groups_changed || requested_grids_changed) {
539 resetAtomList(msg->
newaid);
542 resetGroupList(msg->
newgdef,&totalGroupsRequested);
543 numDataSenders = totalAtomsRequested;
547 for ( ; g_i != g_e; ++g_i ) {
550 iout <<
iWARN <<
"Atom " << (*g_i+1) <<
" has a near-zero mass, " 551 <<
"but it was requested for center-of-mass calculation.\n" 560 numForceSenders = (forceSendActive ? numDataSenders : 0);
567 gm_i = receivedGroupMasses.
begin();
568 for ( ; gf_i < gf_e; ++gf_i, ++gm_i ) { *gf_i /= *gm_i; }
571 DebugM(3,
"Sending results ("<<totalAtomsRequested<<
" atoms requested, " 572 <<totalGroupsRequested<<
" groups requested, " 573 <<msg->
f.
size()<<
" forces set)\n");
574 myComputeManager->sendComputeGlobalResults(msg);
580 int theNumDataSenders) {
581 DebugM(3,
"Constructing GlobalMasterServer\n");
582 myComputeManager = m;
589 recvPatchesCount = 0;
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");
int old_num_groups_requested
#define NAMD_EVENT_STOP(eon, id)
static PatchMap * Object()
BigRealList gridobjvalue
Partial values of the GridForce objects from this message.
SimParameters * simParameters
std::ostream & endi(std::ostream &s)
bool requestedTotalForces()
std::ostream & iWARN(std::ostream &s)
int add(const Elem &elem)
Molecule stores the structural information for the system.
const ResizeArray< AtomIDList > & requestedGroups()
void processData(AtomIDList::iterator a_i, AtomIDList::iterator a_e, PositionList::iterator p_i, PositionList::iterator g_i, PositionList::iterator g_e, BigRealList::iterator gm_i, BigRealList::iterator gm_e, ForceList::iterator gtf_i, ForceList::iterator gtf_e, IntList::iterator goi_i, IntList::iterator goi_e, BigRealList::iterator gov_i, BigRealList::iterator gov_e, AtomIDList::iterator last_atoms_forced_i, AtomIDList::iterator last_atoms_forced_e, ForceList::iterator last_forces_i, AtomIDList::iterator, AtomIDList::iterator, ForceList::iterator)
void setall(const Elem &elem)
void setLattice(const Lattice *lat)
int numPatches(void) const
#define NAMD_EVENT_START(eon, id)
void NAMD_bug(const char *err_msg)
ResizeArray< Lattice > lat
IntList gridobjindex
Indices of the GridForce objects contained in this message.
Real atommass(int anum) const
void recvData(ComputeGlobalDataMsg *)
void addClient(GlobalMaster *newClient)
const BigRealList & gridObjForces()
int count
Numer of atoms processed for this message.
GlobalMasterServer(ComputeMgr *m, int theNumDataSenders)
const IntList & requestedGridObjs()
int patchcount
Number of patches processed for this message.
int globalMasterFrequency
virtual ~GlobalMasterServer()
const AtomIDList & requestedAtoms()