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

#include <ComputeGlobal.h>

Inheritance diagram for ComputeGlobal:
ComputeHomePatches Compute

Public Member Functions

 ComputeGlobal (ComputeID, ComputeMgr *)
 
virtual ~ComputeGlobal ()
 
void doWork ()
 
void recvResults (ComputeGlobalResultsMsg *)
 
void saveTotalForces (HomePatch *)
 
- Public Member Functions inherited from ComputeHomePatches
 ComputeHomePatches (ComputeID c)
 
virtual ~ComputeHomePatches ()
 
virtual void initialize ()
 
virtual void atomUpdate ()
 
FlagsgetFlags (void)
 
- Public Member Functions inherited from Compute
 Compute (ComputeID)
 
int type ()
 
virtual ~Compute ()
 
void setNumPatches (int n)
 
int getNumPatches ()
 
virtual void patchReady (PatchID, int doneMigration, int seq)
 
virtual int noWork ()
 
virtual void finishPatch (int)
 
int sequence (void)
 
int priority (void)
 
int getGBISPhase (void)
 
virtual void gbisP2PatchReady (PatchID, int seq)
 
virtual void gbisP3PatchReady (PatchID, int seq)
 

Additional Inherited Members

- Public Attributes inherited from Compute
const ComputeID cid
 
LDObjHandle ldObjHandle
 
LocalWorkMsg *const localWorkMsg
 
- Protected Member Functions inherited from Compute
void enqueueWork ()
 
- Protected Attributes inherited from ComputeHomePatches
int useAvgPositions
 
int hasPatchZero
 
ComputeHomePatchList patchList
 
PatchMappatchMap
 
- Protected Attributes inherited from Compute
int computeType
 
int basePriority
 
int gbisPhase
 
int gbisPhasePriority [3]
 

Detailed Description

Definition at line 35 of file ComputeGlobal.h.

Constructor & Destructor Documentation

ComputeGlobal::ComputeGlobal ( ComputeID  c,
ComputeMgr m 
)

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 35 of file ComputeGlobal.C.

References SimParameters::colvarsOn, DebugM, SimParameters::FMAOn, SimParameters::fullDirectOn, SimParameters::GBISOn, SimParameters::GBISserOn, PatchMap::numPatches(), numPatches, PatchMap::Object(), Node::Object(), ReductionMgr::Object(), SimParameters::PMEOn, REDUCTIONS_BASIC, ResizeArray< T >::resize(), Node::simParameters, SimParameters::tclForcesOn, and ReductionMgr::willSubmit().

37 {
38  DebugM(3,"Constructing client\n");
39  aid.resize(0);
40  gdef.resize(0);
41  comm = m;
42  firsttime = 1;
43  isRequested = 0;
44  isRequestedAllocSize = 0;
45  endRequested = 0;
46  numGroupsRequested = 0;
48  dofull = (sp->GBISserOn || sp->GBISOn || sp->fullDirectOn || sp->FMAOn || sp->PMEOn);
49  forceSendEnabled = 0;
50  if ( sp->tclForcesOn ) forceSendEnabled = 1;
51  if ( sp->colvarsOn ) forceSendEnabled = 1;
52  forceSendActive = 0;
53  fid.resize(0);
54  totalForce.resize(0);
55  gfcount = 0;
56  groupTotalForce.resize(0);
59  forcePtrs = new Force*[numPatches];
60  atomPtrs = new FullAtom*[numPatches];
61  gridForcesPtrs = new ForceList **[numPatches];
62  numGridObjects = numActiveGridObjects = 0;
63  for ( int i = 0; i < numPatches; ++i ) {
64  forcePtrs[i] = NULL; atomPtrs[i] = NULL;
65  gridForcesPtrs[i] = NULL;
66  }
67 }
static Node * Object()
Definition: Node.h:86
static PatchMap * Object()
Definition: PatchMap.h:27
Definition: Vector.h:64
SimParameters * simParameters
Definition: Node.h:178
#define DebugM(x, y)
Definition: Debug.h:59
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
ComputeHomePatches(ComputeID c)
__global__ void const int const TileList *__restrict__ TileExcl *__restrict__ const int *__restrict__ const int const float2 *__restrict__ cudaTextureObject_t const int *__restrict__ const float3 const float3 const float3 const float4 *__restrict__ const float cudaTextureObject_t cudaTextureObject_t float const PatchPairRecord *__restrict__ const int *__restrict__ const int2 *__restrict__ const unsigned int *__restrict__ unsigned int *__restrict__ int *__restrict__ int *__restrict__ TileListStat *__restrict__ const BoundingBox *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ float *__restrict__ const int numPatches
int numPatches(void) const
Definition: PatchMap.h:59
void resize(int i)
Definition: ResizeArray.h:84
ComputeGlobal::~ComputeGlobal ( )
virtual

Definition at line 69 of file ComputeGlobal.C.

70 {
71  delete[] isRequested;
72  delete[] forcePtrs;
73  deleteGridObjects();
74  delete[] gridForcesPtrs;
75  delete[] atomPtrs;
76  delete reduction;
77 }

Member Function Documentation

void ComputeGlobal::doWork ( void  )
virtual

Reimplemented from Compute.

Definition at line 322 of file ComputeGlobal.C.

References ResizeArray< T >::add(), ResizeArrayIter< Type >::begin(), ComputeGlobalDataMsg::count, DebugM, ComputeMgr::enableComputeGlobalResults(), ResizeArrayIter< Type >::end(), ComputeHomePatches::hasPatchZero, ComputeGlobalDataMsg::lat, ComputeGlobalDataMsg::patchcount, ComputeHomePatches::patchList, ComputeMgr::sendComputeGlobalData(), ComputeGlobalDataMsg::step, and x.

323 {
324  DebugM(2,"doWork\n");
325 
327  FullAtom **t = atomPtrs;
328 
329  for (ap = ap.begin(); ap != ap.end(); ap++) {
330  CompAtom *x = (*ap).positionBox->open();
331  t[(*ap).patchID] = (*ap).p->getAtomList().begin();
332  }
333 
334  if(!firsttime) sendData();
335  else {
336  if ( hasPatchZero ) {
338  msg->lat.add(patchList[0].p->lattice);
339  msg->step = -1;
340  msg->count = 1;
341  msg->patchcount = 0;
342  comm->sendComputeGlobalData(msg);
343  }
344  firsttime = 0;
346  }
347  DebugM(2,"done with doWork\n");
348 }
ComputeHomePatchList patchList
#define DebugM(x, y)
Definition: Debug.h:59
ResizeArray< Lattice > lat
void enableComputeGlobalResults()
Definition: ComputeMgr.C:1293
int add(const Elem &elem)
Definition: ResizeArray.h:97
int count
Numer of atoms processed for this message.
void sendComputeGlobalData(ComputeGlobalDataMsg *)
Definition: ComputeMgr.C:1272
int patchcount
Number of patches processed for this message.
gridSize x
void ComputeGlobal::recvResults ( ComputeGlobalResultsMsg msg)

Definition at line 210 of file ComputeGlobal.C.

References ADD_TENSOR_OBJECT, ADD_VECTOR_OBJECT, ComputeGlobalResultsMsg::aid, ResizeArray< T >::begin(), ResizeArrayIter< Type >::begin(), DebugM, ResizeArray< T >::end(), ResizeArrayIter< Type >::end(), ComputeGlobalResultsMsg::f, ComputeGlobalResultsMsg::gforce, LocalID::index, AtomMap::localID(), FullAtom::mass, NAMD_bug(), ComputeGlobalResultsMsg::newaid, ComputeGlobalResultsMsg::newgdef, ComputeGlobalResultsMsg::newgridobjid, Results::normal, notUsed, AtomMap::Object(), outer(), ComputeHomePatches::patchList, LocalID::pid, CompAtom::position, ComputeGlobalResultsMsg::reconfig, ComputeGlobalResultsMsg::resendCoordinates, ResizeArray< T >::resize(), Lattice::reverse_transform(), ResizeArray< T >::size(), SubmitReduction::submit(), ComputeGlobalResultsMsg::totalforces, FullAtom::transform, and x.

Referenced by ComputeMgr::recvComputeGlobalResults().

210  {
211  DebugM(3,"Receiving results (" << msg->aid.size() << " forces, "
212  << msg->newgdef.size() << " new group atoms) on client\n");
213 
214  forceSendActive = msg->totalforces;
215  if ( forceSendActive && ! forceSendEnabled ) NAMD_bug("ComputeGlobal::recvResults forceSendActive without forceSendEnabled");
216 
217  // set the forces only if we aren't going to resend the data
218  int setForces = !msg->resendCoordinates;
219 
220  if(setForces) { // we are requested to
221  // Store forces to patches
222  AtomMap *atomMap = AtomMap::Object();
223  const Lattice & lattice = patchList[0].p->lattice;
225  Force **f = forcePtrs;
226  FullAtom **t = atomPtrs;
227  Force extForce = 0.;
228  Tensor extVirial;
229 
230  for (ap = ap.begin(); ap != ap.end(); ap++) {
231  (*ap).r = (*ap).forceBox->open();
232  f[(*ap).patchID] = (*ap).r->f[Results::normal];
233  t[(*ap).patchID] = (*ap).p->getAtomList().begin();
234  }
235 
236  AtomIDList::iterator a = msg->aid.begin();
237  AtomIDList::iterator a_e = msg->aid.end();
238  ForceList::iterator f2 = msg->f.begin();
239  for ( ; a != a_e; ++a, ++f2 ) {
240  DebugM(1,"processing atom "<<(*a)<<", F="<<(*f2)<<"...\n");
241  /* XXX if (*a) is out of bounds here we get a segfault */
242  LocalID localID = atomMap->localID(*a);
243  if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
244  Force f_atom = (*f2);
245  f[localID.pid][localID.index] += f_atom;
246  FullAtom &atom = t[localID.pid][localID.index];
247  Position x_orig = atom.position;
248  Transform trans = atom.transform;
249  Position x_atom = lattice.reverse_transform(x_orig,trans);
250  extForce += f_atom;
251  extVirial += outer(f_atom,x_atom);
252  }
253  DebugM(1,"done with the loop\n");
254 
255  // calculate forces for atoms in groups
256  AtomIDList::iterator g_i, g_e;
257  g_i = gdef.begin(); g_e = gdef.end();
258  ForceList::iterator gf_i = msg->gforce.begin();
259  //iout << iDEBUG << "recvResults\n" << endi;
260  for ( ; g_i != g_e; ++g_i, ++gf_i ) {
261  //iout << iDEBUG << *gf_i << '\n' << endi;
262  Vector accel = (*gf_i);
263  for ( ; *g_i != -1; ++g_i ) {
264  //iout << iDEBUG << *g_i << '\n' << endi;
265  LocalID localID = atomMap->localID(*g_i);
266  if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
267  FullAtom &atom = t[localID.pid][localID.index];
268  Force f_atom = accel * atom.mass;
269  f[localID.pid][localID.index] += f_atom;
270  Position x_orig = atom.position;
271  Transform trans = atom.transform;
272  Position x_atom = lattice.reverse_transform(x_orig,trans);
273  extForce += f_atom;
274  extVirial += outer(f_atom,x_atom);
275  }
276  }
277  DebugM(1,"done with the groups\n");
278 
279  if (numActiveGridObjects > 0) {
280  applyGridObjectForces(msg, &extForce, &extVirial);
281  }
282 
283  ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
284  ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
285  reduction->submit();
286  }
287  // done setting the forces, close boxes below
288 
289  // Get reconfiguration if present
290  if ( msg->reconfig ) {
291  DebugM(3,"Reconfiguring\n");
292  configure(msg->newaid, msg->newgdef, msg->newgridobjid);
293  }
294 
295  // send another round of data if requested
296 
297  if(msg->resendCoordinates) {
298  DebugM(3,"Sending requested data right away\n");
299  sendData();
300  }
301 
302  groupTotalForce.resize(numGroupsRequested);
303  for ( int i=0; i<numGroupsRequested; ++i ) groupTotalForce[i] = 0;
304 
305  if(setForces) {
307  Force **f = forcePtrs;
308  FullAtom **t = atomPtrs;
309  for (ap = ap.begin(); ap != ap.end(); ap++) {
310  CompAtom *x;
311  (*ap).positionBox->close(&x);
312  (*ap).forceBox->close(&((*ap).r));
313  f[(*ap).patchID] = 0;
314  t[(*ap).patchID] = 0;
315  }
316  }
317 
318  delete msg;
319  DebugM(3,"Done processing results\n");
320 }
Definition: Vector.h:64
#define ADD_TENSOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:43
ComputeHomePatchList patchList
#define DebugM(x, y)
Definition: Debug.h:59
Position position
Definition: NamdTypes.h:53
void NAMD_bug(const char *err_msg)
Definition: common.C:129
int index
Definition: NamdTypes.h:195
iterator end(void)
Definition: ResizeArray.h:37
LocalID localID(AtomID id)
Definition: AtomMap.h:74
PatchID pid
Definition: NamdTypes.h:194
static AtomMap * Object()
Definition: AtomMap.h:36
Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
void resize(int i)
Definition: ResizeArray.h:84
Position reverse_transform(Position data, const Transform &t) const
Definition: Lattice.h:138
Definition: Tensor.h:15
Mass mass
Definition: NamdTypes.h:108
#define ADD_VECTOR_OBJECT(R, RL, D)
Definition: ReductionMgr.h:27
void submit(void)
Definition: ReductionMgr.h:323
int size(void) const
Definition: ResizeArray.h:127
gridSize x
Transform transform
Definition: NamdTypes.h:116
iterator begin(void)
Definition: ResizeArray.h:36
void ComputeGlobal::saveTotalForces ( HomePatch homePatch)

Definition at line 612 of file ComputeGlobal.C.

References SimParameters::accelMDDebugOn, SimParameters::accelMDdihe, ResizeArray< T >::add(), Results::amdf, atoms, ResizeArray< T >::begin(), ResizeArray< T >::end(), Patch::f, intpair::first, SimParameters::fixedAtomsOn, NAMD_bug(), Results::nbond, Results::normal, Patch::numAtoms, Node::Object(), intpair::second, Node::simParameters, and Results::slow.

Referenced by Sequencer::integrate(), and Sequencer::minimize().

613 {
614  if ( ! forceSendEnabled ) NAMD_bug("ComputeGlobal::saveTotalForces called unexpectedly");
615  if ( ! forceSendActive ) return;
616 
617  if ( Node::Object()->simParameters->accelMDOn && Node::Object()->simParameters->accelMDDebugOn && Node::Object()->simParameters->accelMDdihe ) {
618  int num=homePatch->numAtoms;
619  FullAtomList &atoms = homePatch->atom;
620  ForceList &af=homePatch->f[Results::amdf];
621 
622  for (int i=0; i<num; ++i) {
623  int index = atoms[i].id;
624  if (index < endRequested && isRequested[index] & 1) {
625  fid.add(index);
626  totalForce.add(af[i]);
627  }
628  }
629  return;
630  }
631 
632  int fixedAtomsOn = Node::Object()->simParameters->fixedAtomsOn;
633  int num=homePatch->numAtoms;
634  FullAtomList &atoms = homePatch->atom;
635  ForceList &f1=homePatch->f[Results::normal], &f2=homePatch->f_saved[Results::nbond],
636  &f3=homePatch->f_saved[Results::slow];
637  Force f_sum;
638 
639  for (int i=0; i<num; ++i) {
640  int index = atoms[i].id;
641  char reqflag;
642  if (index < endRequested && (reqflag = isRequested[index])) {
643  f_sum = f1[i]+f2[i];
644  if (dofull)
645  f_sum += f3[i];
646  if ( fixedAtomsOn && atoms[i].atomFixed ) f_sum = 0.;
647  if ( reqflag & 1 ) { // individual atom
648  fid.add(index);
649  totalForce.add(f_sum);
650  }
651  if ( reqflag & 2 ) { // part of group
652  intpair *gpend = gpair.end();
653  intpair *gpi = std::lower_bound(gpair.begin(),gpend,intpair(index,0));
654  if ( gpi == gpend || gpi->first != index )
655  NAMD_bug("ComputeGlobal::saveTotalForces gpair corrupted.");
656  do {
657  ++gfcount;
658  groupTotalForce[gpi->second] += f_sum;
659  } while ( ++gpi != gpend && gpi->first == index );
660  }
661  }
662  }
663 }
static Node * Object()
Definition: Node.h:86
Definition: Vector.h:64
SimParameters * simParameters
Definition: Node.h:178
static __thread atom * atoms
int second
Definition: ComputeGlobal.h:24
void NAMD_bug(const char *err_msg)
Definition: common.C:129
iterator end(void)
Definition: ResizeArray.h:37
int numAtoms
Definition: Patch.h:144
int add(const Elem &elem)
Definition: ResizeArray.h:97
ForceList f[Results::maxNumForces]
Definition: Patch.h:207
iterator begin(void)
Definition: ResizeArray.h:36

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