ComputeGlobal Class Reference

#include <ComputeGlobal.h>

Inheritance diagram for ComputeGlobal:
ComputeHomePatches Compute

List of all members.

Public Member Functions

 ComputeGlobal (ComputeID, ComputeMgr *)
virtual ~ComputeGlobal ()
void doWork ()
void recvResults (ComputeGlobalResultsMsg *)
void saveTotalForces (HomePatch *)

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(), ReductionMgr::Object(), Node::Object(), SimParameters::PMEOn, REDUCTIONS_BASIC, ResizeArray< Elem >::resize(), Node::simParameters, SimParameters::tclForcesOn, and ReductionMgr::willSubmit().

00036   : ComputeHomePatches(c)
00037 {
00038   DebugM(3,"Constructing client\n");
00039   aid.resize(0);
00040   gdef.resize(0);
00041   comm = m;
00042   firsttime = 1;
00043   isRequested = 0;
00044   isRequestedAllocSize = 0;
00045   endRequested = 0;
00046   numGroupsRequested = 0;
00047   SimParameters *sp = Node::Object()->simParameters;
00048   dofull = (sp->GBISserOn || sp->GBISOn || sp->fullDirectOn || sp->FMAOn || sp->PMEOn);
00049   forceSendEnabled = 0;
00050   if ( sp->tclForcesOn ) forceSendEnabled = 1;
00051   if ( sp->colvarsOn ) forceSendEnabled = 1;
00052   forceSendActive = 0;
00053   fid.resize(0);
00054   totalForce.resize(0);
00055   gfcount = 0;
00056   groupTotalForce.resize(0);
00057   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00058   int numPatches = PatchMap::Object()->numPatches();
00059   forcePtrs = new Force*[numPatches];
00060   atomPtrs = new FullAtom*[numPatches];
00061   gridForcesPtrs = new ForceList **[numPatches];
00062   numGridObjects = numActiveGridObjects = 0;
00063   for ( int i = 0; i < numPatches; ++i ) {
00064     forcePtrs[i] = NULL; atomPtrs[i] = NULL;
00065     gridForcesPtrs[i] = NULL;
00066   }
00067 }

ComputeGlobal::~ComputeGlobal (  )  [virtual]

Definition at line 69 of file ComputeGlobal.C.

00070 {
00071   delete[] isRequested;
00072   delete[] forcePtrs;
00073   deleteGridObjects();
00074   delete[] gridForcesPtrs;
00075   delete[] atomPtrs;
00076   delete reduction;
00077 }


Member Function Documentation

void ComputeGlobal::doWork ( void   )  [virtual]

Reimplemented from Compute.

Definition at line 322 of file ComputeGlobal.C.

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

00323 {
00324   DebugM(2,"doWork\n");
00325 
00326   ResizeArrayIter<PatchElem> ap(patchList);
00327   FullAtom **t = atomPtrs;
00328 
00329   for (ap = ap.begin(); ap != ap.end(); ap++) {
00330     CompAtom *x = (*ap).positionBox->open();
00331     t[(*ap).patchID] = (*ap).p->getAtomList().begin();
00332   }
00333 
00334   if(!firsttime) sendData();
00335   else {
00336     if ( hasPatchZero ) {
00337       ComputeGlobalDataMsg *msg = new ComputeGlobalDataMsg;
00338       msg->lat.add(patchList[0].p->lattice);
00339       msg->step = -1;
00340       msg->count = 1;
00341       msg->patchcount = 0;
00342       comm->sendComputeGlobalData(msg);
00343     }
00344     firsttime = 0;
00345     comm->enableComputeGlobalResults();
00346   }
00347   DebugM(2,"done with doWork\n");
00348 }

void ComputeGlobal::recvResults ( ComputeGlobalResultsMsg msg  ) 

Definition at line 210 of file ComputeGlobal.C.

References ADD_TENSOR_OBJECT, ADD_VECTOR_OBJECT, ComputeGlobalResultsMsg::aid, ResizeArray< Elem >::begin(), ResizeArrayIter< T >::begin(), DebugM, ResizeArray< Elem >::end(), ResizeArrayIter< T >::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< Elem >::resize(), Lattice::reverse_transform(), ResizeArray< Elem >::size(), SubmitReduction::submit(), ComputeGlobalResultsMsg::totalforces, and FullAtom::transform.

Referenced by ComputeMgr::recvComputeGlobalResults().

00210                                                             {
00211   DebugM(3,"Receiving results (" << msg->aid.size() << " forces, "
00212          << msg->newgdef.size() << " new group atoms) on client\n");
00213 
00214   forceSendActive = msg->totalforces;
00215   if ( forceSendActive && ! forceSendEnabled ) NAMD_bug("ComputeGlobal::recvResults forceSendActive without forceSendEnabled");
00216 
00217   // set the forces only if we aren't going to resend the data
00218   int setForces = !msg->resendCoordinates;
00219 
00220   if(setForces) { // we are requested to 
00221     // Store forces to patches
00222     AtomMap *atomMap = AtomMap::Object();
00223     const Lattice & lattice = patchList[0].p->lattice;
00224     ResizeArrayIter<PatchElem> ap(patchList);
00225     Force **f = forcePtrs;
00226     FullAtom **t = atomPtrs;
00227     Force extForce = 0.;
00228     Tensor extVirial;
00229 
00230     for (ap = ap.begin(); ap != ap.end(); ap++) {
00231       (*ap).r = (*ap).forceBox->open();
00232       f[(*ap).patchID] = (*ap).r->f[Results::normal];
00233       t[(*ap).patchID] = (*ap).p->getAtomList().begin();
00234     }
00235 
00236     AtomIDList::iterator a = msg->aid.begin();
00237     AtomIDList::iterator a_e = msg->aid.end();
00238     ForceList::iterator f2 = msg->f.begin();
00239     for ( ; a != a_e; ++a, ++f2 ) {
00240       DebugM(1,"processing atom "<<(*a)<<", F="<<(*f2)<<"...\n");
00241       /* XXX if (*a) is out of bounds here we get a segfault */
00242       LocalID localID = atomMap->localID(*a);
00243       if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00244       Force f_atom = (*f2);
00245       f[localID.pid][localID.index] += f_atom;
00246       FullAtom &atom = t[localID.pid][localID.index];
00247       Position x_orig = atom.position;
00248       Transform trans = atom.transform;
00249       Position x_atom = lattice.reverse_transform(x_orig,trans);
00250       extForce += f_atom;
00251       extVirial += outer(f_atom,x_atom);
00252     }
00253     DebugM(1,"done with the loop\n");
00254 
00255     // calculate forces for atoms in groups
00256     AtomIDList::iterator g_i, g_e;
00257     g_i = gdef.begin(); g_e = gdef.end();
00258     ForceList::iterator gf_i = msg->gforce.begin();
00259     //iout << iDEBUG << "recvResults\n" << endi;
00260     for ( ; g_i != g_e; ++g_i, ++gf_i ) {
00261       //iout << iDEBUG << *gf_i << '\n' << endi;
00262       Vector accel = (*gf_i);
00263       for ( ; *g_i != -1; ++g_i ) {
00264         //iout << iDEBUG << *g_i << '\n' << endi;
00265         LocalID localID = atomMap->localID(*g_i);
00266         if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00267         FullAtom &atom = t[localID.pid][localID.index];
00268         Force f_atom = accel * atom.mass;
00269         f[localID.pid][localID.index] += f_atom;
00270         Position x_orig = atom.position;
00271         Transform trans = atom.transform;
00272         Position x_atom = lattice.reverse_transform(x_orig,trans);
00273         extForce += f_atom;
00274         extVirial += outer(f_atom,x_atom);
00275       }
00276     }
00277     DebugM(1,"done with the groups\n");
00278 
00279     if (numActiveGridObjects > 0) {
00280       applyGridObjectForces(msg, &extForce, &extVirial);
00281     }
00282 
00283     ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
00284     ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
00285     reduction->submit();
00286   }
00287   // done setting the forces, close boxes below
00288 
00289   // Get reconfiguration if present
00290   if ( msg->reconfig ) {
00291     DebugM(3,"Reconfiguring\n");
00292     configure(msg->newaid, msg->newgdef, msg->newgridobjid);
00293   }
00294 
00295   // send another round of data if requested
00296 
00297   if(msg->resendCoordinates) {
00298     DebugM(3,"Sending requested data right away\n");
00299     sendData();
00300   }
00301 
00302   groupTotalForce.resize(numGroupsRequested);
00303   for ( int i=0; i<numGroupsRequested; ++i ) groupTotalForce[i] = 0;
00304 
00305   if(setForces) {
00306     ResizeArrayIter<PatchElem> ap(patchList);
00307     Force **f = forcePtrs;
00308     FullAtom **t = atomPtrs;
00309     for (ap = ap.begin(); ap != ap.end(); ap++) {
00310       CompAtom *x;
00311       (*ap).positionBox->close(&x);
00312       (*ap).forceBox->close(&((*ap).r));
00313       f[(*ap).patchID] = 0;
00314       t[(*ap).patchID] = 0;
00315     }
00316   }
00317 
00318   delete msg;
00319   DebugM(3,"Done processing results\n");
00320 }

void ComputeGlobal::saveTotalForces ( HomePatch homePatch  ) 

Definition at line 612 of file ComputeGlobal.C.

References SimParameters::accelMDDebugOn, SimParameters::accelMDdihe, ResizeArray< Elem >::add(), Results::amdf, atoms, ResizeArray< Elem >::begin(), ResizeArray< Elem >::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().

00613 {
00614   if ( ! forceSendEnabled ) NAMD_bug("ComputeGlobal::saveTotalForces called unexpectedly");
00615   if ( ! forceSendActive ) return;
00616 
00617   if ( Node::Object()->simParameters->accelMDOn && Node::Object()->simParameters->accelMDDebugOn && Node::Object()->simParameters->accelMDdihe ) {
00618     int num=homePatch->numAtoms;
00619     FullAtomList &atoms = homePatch->atom;
00620     ForceList &af=homePatch->f[Results::amdf];
00621 
00622     for (int i=0; i<num; ++i) {
00623       int index = atoms[i].id;
00624       if (index < endRequested && isRequested[index] & 1) {
00625         fid.add(index);
00626         totalForce.add(af[i]);
00627       }
00628     }
00629     return;
00630   }
00631 
00632   int fixedAtomsOn = Node::Object()->simParameters->fixedAtomsOn;
00633   int num=homePatch->numAtoms;
00634   FullAtomList &atoms = homePatch->atom;
00635   ForceList &f1=homePatch->f[Results::normal], &f2=homePatch->f_saved[Results::nbond],
00636             &f3=homePatch->f_saved[Results::slow];
00637   Force f_sum;
00638   
00639   for (int i=0; i<num; ++i) {
00640     int index = atoms[i].id;
00641     char reqflag;
00642     if (index < endRequested && (reqflag = isRequested[index])) {
00643      f_sum = f1[i]+f2[i];
00644      if (dofull)
00645        f_sum += f3[i];
00646      if ( fixedAtomsOn && atoms[i].atomFixed ) f_sum = 0.;
00647      if ( reqflag  & 1 ) {  // individual atom
00648       fid.add(index);
00649       totalForce.add(f_sum);
00650      }
00651      if ( reqflag  & 2 ) {  // part of group
00652        intpair *gpend = gpair.end();
00653        intpair *gpi = std::lower_bound(gpair.begin(),gpend,intpair(index,0));
00654        if ( gpi == gpend || gpi->first != index )
00655          NAMD_bug("ComputeGlobal::saveTotalForces gpair corrupted.");
00656        do {
00657          ++gfcount;
00658          groupTotalForce[gpi->second] += f_sum;
00659        } while ( ++gpi != gpend && gpi->first == index );
00660      }
00661     }
00662   }
00663 }


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

Generated on 21 Sep 2020 for NAMD by  doxygen 1.6.1