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  ,
ComputeMgr  
)

Definition at line 33 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().

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

ComputeGlobal::~ComputeGlobal (  )  [virtual]

Definition at line 62 of file ComputeGlobal.C.

00063 {
00064   delete[] isRequested;
00065   delete[] forcePtrs;
00066   delete[] atomPtrs;
00067   delete reduction;
00068 }


Member Function Documentation

void ComputeGlobal::doWork (  )  [virtual]

Reimplemented from Compute.

Definition at line 240 of file ComputeGlobal.C.

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

00241 {
00242   DebugM(2,"doWork\n");
00243 
00244   ResizeArrayIter<PatchElem> ap(patchList);
00245   FullAtom **t = atomPtrs;
00246 
00247   for (ap = ap.begin(); ap != ap.end(); ap++) {
00248     CompAtom *x = (*ap).positionBox->open();
00249     t[(*ap).patchID] = (*ap).p->getAtomList().begin();
00250   }
00251 
00252   if(!firsttime) sendData();
00253   else {
00254     if ( hasPatchZero ) {
00255       ComputeGlobalDataMsg *msg = new ComputeGlobalDataMsg;
00256       msg->lat.add(patchList[0].p->lattice);
00257       msg->step = -1;
00258       msg->count = 1;
00259       comm->sendComputeGlobalData(msg);
00260     }
00261     firsttime = 0;
00262     comm->enableComputeGlobalResults();
00263   }
00264   DebugM(2,"done with doWork\n");
00265 }

void ComputeGlobal::recvResults ( ComputeGlobalResultsMsg  ) 

Definition at line 135 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, f, ComputeGlobalResultsMsg::gforce, LocalID::index, AtomMap::localID(), FullAtom::mass, NAMD_bug(), ComputeGlobalResultsMsg::newaid, ComputeGlobalResultsMsg::newgdef, Results::normal, notUsed, AtomMap::Object(), outer(), ComputeHomePatches::patchList, LocalID::pid, CompAtom::position, ComputeGlobalResultsMsg::reconfig, REDUCTION_EXT_FORCE_NORMAL, REDUCTION_VIRIAL_NORMAL, ComputeGlobalResultsMsg::resendCoordinates, ResizeArray< Elem >::resize(), Lattice::reverse_transform(), ResizeArray< Elem >::size(), SubmitReduction::submit(), ComputeGlobalResultsMsg::totalforces, FullAtom::transform, and x.

Referenced by ComputeMgr::recvComputeGlobalResults().

00135                                                             {
00136   DebugM(3,"Receiving results (" << msg->aid.size() << " forces, "
00137          << msg->newgdef.size() << " new group atoms) on client\n");
00138 
00139   forceSendActive = msg->totalforces;
00140   if ( forceSendActive && ! forceSendEnabled ) NAMD_bug("ComputeGlobal::recvResults forceSendActive without forceSendEnabled");
00141 
00142   // set the forces only if we aren't going to resend the data
00143   int setForces = !msg->resendCoordinates;
00144 
00145   if(setForces) { // we are requested to 
00146     // Store forces to patches
00147     AtomMap *atomMap = AtomMap::Object();
00148     const Lattice & lattice = patchList[0].p->lattice;
00149     ResizeArrayIter<PatchElem> ap(patchList);
00150     Force **f = forcePtrs;
00151     FullAtom **t = atomPtrs;
00152     Force extForce = 0.;
00153     Tensor extVirial;
00154 
00155     for (ap = ap.begin(); ap != ap.end(); ap++) {
00156       (*ap).r = (*ap).forceBox->open();
00157       f[(*ap).patchID] = (*ap).r->f[Results::normal];
00158       t[(*ap).patchID] = (*ap).p->getAtomList().begin();
00159     }
00160 
00161     AtomIDList::iterator a = msg->aid.begin();
00162     AtomIDList::iterator a_e = msg->aid.end();
00163     ForceList::iterator f2 = msg->f.begin();
00164     for ( ; a != a_e; ++a, ++f2 ) {
00165       DebugM(1,"processing atom "<<(*a)<<", F="<<(*f2)<<"...\n");
00166       /* XXX if (*a) is out of bounds here we get a segfault */
00167       LocalID localID = atomMap->localID(*a);
00168       if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00169       Force f_atom = (*f2);
00170       f[localID.pid][localID.index] += f_atom;
00171       FullAtom &atom = t[localID.pid][localID.index];
00172       Position x_orig = atom.position;
00173       Transform trans = atom.transform;
00174       Position x_atom = lattice.reverse_transform(x_orig,trans);
00175       extForce += f_atom;
00176       extVirial += outer(f_atom,x_atom);
00177     }
00178     DebugM(1,"done with the loop\n");
00179 
00180   // calculate forces for atoms in groups
00181     AtomIDList::iterator g_i, g_e;
00182     g_i = gdef.begin(); g_e = gdef.end();
00183     ForceList::iterator gf_i = msg->gforce.begin();
00184     //iout << iDEBUG << "recvResults\n" << endi;
00185     for ( ; g_i != g_e; ++g_i, ++gf_i ) {
00186       //iout << iDEBUG << *gf_i << '\n' << endi;
00187       Vector accel = (*gf_i);
00188       for ( ; *g_i != -1; ++g_i ) {
00189         //iout << iDEBUG << *g_i << '\n' << endi;
00190         LocalID localID = atomMap->localID(*g_i);
00191         if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00192         FullAtom &atom = t[localID.pid][localID.index];
00193         Force f_atom = accel * atom.mass;
00194         f[localID.pid][localID.index] += f_atom;
00195         Position x_orig = atom.position;
00196         Transform trans = atom.transform;
00197         Position x_atom = lattice.reverse_transform(x_orig,trans);
00198         extForce += f_atom;
00199         extVirial += outer(f_atom,x_atom);
00200       }
00201     }
00202     DebugM(1,"done with the groups\n");
00203 
00204     ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
00205     ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
00206     reduction->submit();
00207   }
00208   // done setting the forces, close boxes below
00209 
00210   // Get reconfiguration if present
00211   if ( msg->reconfig ) configure(msg->newaid, msg->newgdef);
00212 
00213   // send another round of data if requested
00214 
00215   if(msg->resendCoordinates) {
00216     DebugM(3,"Sending requested data right away\n");
00217     sendData();
00218   }
00219 
00220   groupTotalForce.resize(numGroupsRequested);
00221   for ( int i=0; i<numGroupsRequested; ++i ) groupTotalForce[i] = 0;
00222 
00223   if(setForces) {
00224     ResizeArrayIter<PatchElem> ap(patchList);
00225     Force **f = forcePtrs;
00226     FullAtom **t = atomPtrs;
00227     for (ap = ap.begin(); ap != ap.end(); ap++) {
00228       CompAtom *x;
00229       (*ap).positionBox->close(&x);
00230       (*ap).forceBox->close(&((*ap).r));
00231       f[(*ap).patchID] = 0;
00232       t[(*ap).patchID] = 0;
00233     }
00234   }
00235 
00236   delete msg;
00237   DebugM(3,"Done processing results\n");
00238 }

void ComputeGlobal::saveTotalForces ( HomePatch  ) 

Definition at line 340 of file ComputeGlobal.C.

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

00341 {
00342   if ( ! forceSendEnabled ) NAMD_bug("ComputeGlobal::saveTotalForces called unexpectedly");
00343   if ( ! forceSendActive ) return;
00344 
00345   if ( Node::Object()->simParameters->accelMDOn && Node::Object()->simParameters->accelMDDebugOn && Node::Object()->simParameters->accelMDdihe ) {
00346     int num=homePatch->numAtoms;
00347     FullAtomList &atoms = homePatch->atom;
00348     ForceList &af=homePatch->f[Results::amdf];
00349 
00350     for (int i=0; i<num; ++i) {
00351       int index = atoms[i].id;
00352       if (index < endRequested && isRequested[index] & 1) {
00353         fid.add(index);
00354         totalForce.add(af[i]);
00355       }
00356     }
00357     return;
00358   }
00359 
00360   int fixedAtomsOn = Node::Object()->simParameters->fixedAtomsOn;
00361   int num=homePatch->numAtoms;
00362   FullAtomList &atoms = homePatch->atom;
00363   ForceList &f1=homePatch->f[Results::normal], &f2=homePatch->f_saved[Results::nbond],
00364             &f3=homePatch->f_saved[Results::slow];
00365   Force f_sum;
00366   
00367   for (int i=0; i<num; ++i) {
00368     int index = atoms[i].id;
00369     char reqflag;
00370     if (index < endRequested && (reqflag = isRequested[index])) {
00371      f_sum = f1[i]+f2[i];
00372      if (dofull)
00373        f_sum += f3[i];
00374      if ( fixedAtomsOn && atoms[i].atomFixed ) f_sum = 0.;
00375      if ( reqflag  & 1 ) {  // individual atom
00376       fid.add(index);
00377       totalForce.add(f_sum);
00378      }
00379      if ( reqflag  & 2 ) {  // part of group
00380        intpair *gpend = gpair.end();
00381        intpair *gpi = std::lower_bound(gpair.begin(),gpend,intpair(index,0));
00382        if ( gpi == gpend || gpi->first != index )
00383          NAMD_bug("ComputeGlobal::saveTotalForces gpair corrupted.");
00384        do {
00385          ++gfcount;
00386          groupTotalForce[gpi->second] += f_sum;
00387        } while ( ++gpi != gpend && gpi->first == index );
00388      }
00389     }
00390   }
00391 }


The documentation for this class was generated from the following files:
Generated on Sat Sep 23 01:17:18 2017 for NAMD by  doxygen 1.4.7