ComputeHomeTuples< T, S, P > Class Template Reference

#include <ComputeHomeTuples.h>

Inheritance diagram for ComputeHomeTuples< T, S, P >:

Compute ComputeAngles ComputeAniso ComputeBonds ComputeCrossterms ComputeDihedrals ComputeGromacsPair ComputeImpropers ComputeSelfTuples< T, S, P > ComputeSelfTuples< AngleElem, angle, AngleValue > ComputeSelfTuples< AnisoElem, aniso, aniso > ComputeSelfTuples< BondElem, bond, BondValue > ComputeSelfTuples< CrosstermElem, crossterm, CrosstermValue > ComputeSelfTuples< DihedralElem, dihedral, DihedralValue > ComputeSelfTuples< ExclElem, Exclusion, int > ComputeSelfTuples< GromacsPairElem, gromacsPair, GromacsPairValue > ComputeSelfTuples< ImproperElem, improper, ImproperValue > ComputeSelfTuples< TholeElem, thole, thole > ComputeThole List of all members.

Public Member Functions

virtual ~ComputeHomeTuples ()
virtual void initialize (void)
void atomUpdate (void)
virtual void doWork (void)

Protected Member Functions

virtual void loadTuples (void)
 ComputeHomeTuples (ComputeID c)
 ComputeHomeTuples (ComputeID c, PatchIDList &pids)

Protected Attributes

int doLoadTuples
ResizeArray< T > tupleList
TuplePatchList tuplePatchList
PatchMappatchMap
AtomMapatomMap
SubmitReductionreduction
int accelMDdoDihe
SubmitReductionpressureProfileReduction
BigRealpressureProfileData
int pressureProfileSlabs
char * isBasePatch

Detailed Description

template<class T, class S, class P>
class ComputeHomeTuples< T, S, P >

Definition at line 309 of file ComputeHomeTuples.h.


Constructor & Destructor Documentation

template<class T, class S, class P>
ComputeHomeTuples< T, S, P >::ComputeHomeTuples ( ComputeID  c  )  [inline, protected]

Definition at line 451 of file ComputeHomeTuples.h.

00451                                    : Compute(c) {
00452       patchMap = PatchMap::Object();
00453       atomMap = AtomMap::Object();
00454       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00455       
00456       SimParameters *params = Node::Object()->simParameters;
00457       accelMDdoDihe=false;
00458       if (params->accelMDOn) {
00459          if (params->accelMDdihe || params->accelMDdual) accelMDdoDihe=true;
00460       }
00461       if (params->pressureProfileOn) {
00462         pressureProfileSlabs = T::pressureProfileSlabs = 
00463           params->pressureProfileSlabs;
00464         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00465         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00466           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00467         int numAtomTypePairs = n*n;
00468         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00469       } else {
00470         pressureProfileReduction = NULL;
00471         pressureProfileData = NULL;
00472       }
00473       doLoadTuples = false;
00474       isBasePatch = 0;
00475 #ifdef USE_HOMETUPLES
00476       tuples = NULL;
00477 #endif
00478     }

template<class T, class S, class P>
ComputeHomeTuples< T, S, P >::ComputeHomeTuples ( ComputeID  c,
PatchIDList pids 
) [inline, protected]

Definition at line 480 of file ComputeHomeTuples.h.

00480                                                       : Compute(c) {
00481       patchMap = PatchMap::Object();
00482       atomMap = AtomMap::Object();
00483       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00484       SimParameters *params = Node::Object()->simParameters;
00485       accelMDdoDihe=false;
00486       if (params->accelMDOn) {
00487          if (params->accelMDdihe || params->accelMDdual) accelMDdoDihe=true;
00488       }
00489       if (params->pressureProfileOn) {
00490         pressureProfileSlabs = T::pressureProfileSlabs = 
00491           params->pressureProfileSlabs;
00492         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00493         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00494           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00495         int numAtomTypePairs = n*n;
00496         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00497       } else {
00498         pressureProfileReduction = NULL;
00499         pressureProfileData = NULL;
00500       }
00501       doLoadTuples = false;
00502       int nPatches = patchMap->numPatches();
00503       isBasePatch = new char[nPatches];
00504       int i;
00505       for (i=0; i<nPatches; ++i) { isBasePatch[i] = 0; }
00506       for (i=0; i<pids.size(); ++i) { isBasePatch[pids[i]] = 1; }
00507 #ifdef USE_HOMETUPLES
00508       tuples = NULL;
00509 #endif
00510     }

template<class T, class S, class P>
virtual ComputeHomeTuples< T, S, P >::~ComputeHomeTuples (  )  [inline, virtual]

Definition at line 514 of file ComputeHomeTuples.h.

00514                                  {
00515       delete reduction;
00516       delete [] isBasePatch;
00517       delete pressureProfileReduction;
00518       delete pressureProfileData;
00519 #ifdef USE_HOMETUPLES
00520       if (tuples != NULL) delete tuples;
00521 #endif
00522     }


Member Function Documentation

template<class T, class S, class P>
void ComputeHomeTuples< T, S, P >::atomUpdate ( void   )  [inline, virtual]

Reimplemented from Compute.

Definition at line 578 of file ComputeHomeTuples.h.

00578                           {
00579       doLoadTuples = true;
00580     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::doWork ( void   )  [inline, virtual]

Reimplemented from Compute.

Reimplemented in ComputeSelfTuples< T, S, P >, ComputeSelfTuples< GromacsPairElem, gromacsPair, GromacsPairValue >, ComputeSelfTuples< AngleElem, angle, AngleValue >, ComputeSelfTuples< ExclElem, Exclusion, int >, ComputeSelfTuples< ImproperElem, improper, ImproperValue >, ComputeSelfTuples< BondElem, bond, BondValue >, ComputeSelfTuples< TholeElem, thole, thole >, ComputeSelfTuples< DihedralElem, dihedral, DihedralValue >, ComputeSelfTuples< CrosstermElem, crossterm, CrosstermValue >, and ComputeSelfTuples< AnisoElem, aniso, aniso >.

Definition at line 587 of file ComputeHomeTuples.h.

Referenced by ComputeSelfTuples< AnisoElem, aniso, aniso >::doWork().

00587                               {
00588 
00589       LdbCoordinator::Object()->startWork(ldObjHandle);
00590 
00591       // Open Boxes - register that we are using Positions
00592       // and will be depositing Forces.
00593       UniqueSetIter<TuplePatchElem> ap(tuplePatchList);
00594       for (ap = ap.begin(); ap != ap.end(); ap++) {
00595         ap->x = ap->positionBox->open();
00596         ap->xExt = ap->p->getCompAtomExtInfo();
00597         if ( ap->p->flags.doMolly ) ap->x_avg = ap->avgPositionBox->open();
00598         ap->r = ap->forceBox->open();
00599         ap->f = ap->r->f[Results::normal];
00600         if (accelMDdoDihe) ap->af = ap->r->f[Results::amdf]; // for dihedral-only or dual-boost accelMD
00601       } 
00602     
00603       BigReal reductionData[T::reductionDataSize];
00604       int tupleCount = 0;
00605       int numAtomTypes = T::pressureProfileAtomTypes;
00606       int numAtomTypePairs = numAtomTypes*numAtomTypes;
00607     
00608       for ( int i = 0; i < T::reductionDataSize; ++i ) reductionData[i] = 0;
00609       if (pressureProfileData) {
00610         memset(pressureProfileData, 0, 3*pressureProfileSlabs*numAtomTypePairs*sizeof(BigReal));
00611         // Silly variable hiding of the previous iterator
00612         UniqueSetIter<TuplePatchElem> newap(tuplePatchList);
00613         newap = newap.begin();
00614         const Lattice &lattice = newap->p->lattice;
00615         T::pressureProfileThickness = lattice.c().z / pressureProfileSlabs;
00616         T::pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
00617       }
00618 
00619       if ( ! Node::Object()->simParameters->commOnly ) {
00620       if ( doLoadTuples ) {
00621 #ifdef USE_HOMETUPLES
00622         tuples->loadTuples(tuplePatchList, isBasePatch, AtomMap::Object());
00623 #else
00624         loadTuples();
00625 #endif
00626         doLoadTuples = false;
00627       }
00628       // take triplet and pass with tuple info to force eval
00629 #ifdef USE_HOMETUPLES
00630       T *al = (T *)tuples->getTupleList();
00631       const int ntuple = tuples->getNumTuples();
00632 #else
00633       T *al = tupleList.begin();
00634       const int ntuple = tupleList.size();
00635 #endif
00636       if ( ntuple ) T::computeForce(al, ntuple, reductionData, pressureProfileData);
00637       tupleCount += ntuple;
00638       }
00639  
00640     LdbCoordinator::Object()->endWork(ldObjHandle);
00641 
00642       T::submitReductionData(reductionData,reduction);
00643       reduction->item(T::reductionChecksumLabel) += (BigReal)tupleCount;
00644       reduction->submit();
00645 
00646       if (pressureProfileReduction) {
00647         // For ease of calculation we stored interactions between types
00648         // i and j in (ni+j).  For efficiency now we coalesce the
00649         // cross interactions so that just i<=j are stored.
00650         const int arraysize = 3*pressureProfileSlabs;
00651         const BigReal *data = pressureProfileData;
00652         for (int i=0; i<numAtomTypes; i++) {
00653           for (int j=0; j<numAtomTypes; j++) {
00654             int ii=i;
00655             int jj=j;
00656             if (ii > jj) { int tmp=ii; ii=jj; jj=tmp; }
00657             const int reductionOffset = 
00658               (ii*numAtomTypes - (ii*(ii+1))/2 + jj)*arraysize;
00659             for (int k=0; k<arraysize; k++) {
00660               pressureProfileReduction->item(reductionOffset+k) += data[k];
00661             }
00662             data += arraysize;
00663           }
00664         }
00665         pressureProfileReduction->submit();
00666       }
00667     
00668       // Close boxes - i.e. signal we are done with Positions and
00669       // AtomProperties and that we are depositing Forces
00670       for (ap = ap.begin(); ap != ap.end(); ap++) {
00671         ap->positionBox->close(&(ap->x));
00672         if ( ap->p->flags.doMolly ) ap->avgPositionBox->close(&(ap->x_avg));
00673         ap->forceBox->close(&(ap->r));
00674       }
00675     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::initialize ( void   )  [inline, virtual]

Reimplemented from Compute.

Reimplemented in ComputeSelfTuples< T, S, P >, ComputeSelfTuples< GromacsPairElem, gromacsPair, GromacsPairValue >, ComputeSelfTuples< AngleElem, angle, AngleValue >, ComputeSelfTuples< ExclElem, Exclusion, int >, ComputeSelfTuples< ImproperElem, improper, ImproperValue >, ComputeSelfTuples< BondElem, bond, BondValue >, ComputeSelfTuples< TholeElem, thole, thole >, ComputeSelfTuples< DihedralElem, dihedral, DihedralValue >, ComputeSelfTuples< CrosstermElem, crossterm, CrosstermValue >, and ComputeSelfTuples< AnisoElem, aniso, aniso >.

Definition at line 528 of file ComputeHomeTuples.h.

00528                                   {
00529 
00530 #ifdef NAMD_CUDA
00531       ProxyMgr *proxyMgr = ProxyMgr::Object();
00532 #endif
00533 
00534 #ifdef USE_HOMETUPLES
00535       tuples = new HomeTuples<T, S, P>();
00536 #endif
00537 
00538       // Start with empty list
00539       tuplePatchList.clear();
00540     
00541       int nPatches = patchMap->numPatches();
00542       int pid;
00543       for (pid=0; pid<nPatches; ++pid) {
00544         if ( isBasePatch[pid] ) {
00545 #ifdef NAMD_CUDA
00546           proxyMgr->createProxy(pid);
00547 #endif
00548           Patch *patch = patchMap->patch(pid);
00549           tuplePatchList.add(TuplePatchElem(patch, this));
00550         }
00551       }
00552     
00553       // Gather all proxy patches (neighbors, that is)
00554       PatchID neighbors[PatchMap::MaxOneOrTwoAway];
00555     
00556       for (pid=0; pid<nPatches; ++pid) if ( isBasePatch[pid] ) {
00557         int numNeighbors = patchMap->upstreamNeighbors(pid,neighbors);
00558         for ( int i = 0; i < numNeighbors; ++i ) {
00559           if ( ! tuplePatchList.find(TuplePatchElem(neighbors[i])) ) {
00560 #ifdef NAMD_CUDA
00561             proxyMgr->createProxy(neighbors[i]);
00562 #endif
00563             Patch *patch = patchMap->patch(neighbors[i]);
00564             tuplePatchList.add(TuplePatchElem(patch, this));
00565           }
00566         }
00567       }
00568       setNumPatches(tuplePatchList.size());
00569       doLoadTuples = true;
00570 
00571       basePriority = COMPUTE_PROXY_PRIORITY;  // no patch dependence
00572     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::loadTuples ( void   )  [inline, protected, virtual]

Definition at line 314 of file ComputeHomeTuples.h.

00314                                   {
00315       int numTuples;
00316 
00317       #ifdef MEM_OPT_VERSION
00318       typename ElemTraits<T>::signature *allSigs;      
00319       #else
00320       int32 **tuplesByAtom;
00321       /* const (need to propagate const) */ S *tupleStructs;
00322       #endif
00323       
00324       const P *tupleValues;
00325       Node *node = Node::Object();
00326 
00327       #ifdef MEM_OPT_VERSION
00328       allSigs = ElemTraits<T>::get_sig_pointer(node->molecule);
00329       #else      
00330       T::getMoleculePointers(node->molecule,
00331                     &numTuples, &tuplesByAtom, &tupleStructs);      
00332       #endif
00333       
00334       T::getParameterPointers(node->parameters, &tupleValues);
00335 
00336       tupleList.resize(0);
00337 
00338       LocalID aid[T::size];
00339 
00340       const int lesOn = node->simParameters->lesOn;
00341       Real invLesFactor = lesOn ? 
00342                           1.0/node->simParameters->lesFactor :
00343                           1.0;
00344 
00345       // cycle through each patch and gather all tuples
00346       TuplePatchListIter ai(tuplePatchList);
00347     
00348       for ( ai = ai.begin(); ai != ai.end(); ai++ )
00349       {
00350         // CompAtom *atom = (*ai).x;
00351         Patch *patch = (*ai).p;
00352         int numAtoms = patch->getNumAtoms();
00353         CompAtomExt *atomExt = (*ai).xExt; //patch->getCompAtomExtInfo();
00354     
00355         // cycle through each atom in the patch and load up tuples
00356         for (int j=0; j < numAtoms; j++)
00357         {              
00358            /* cycle through each tuple */
00359            #ifdef MEM_OPT_VERSION
00360            typename ElemTraits<T>::signature *thisAtomSig =
00361                    &allSigs[ElemTraits<T>::get_sig_id(atomExt[j])];
00362            TupleSignature *allTuples;
00363            T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00364            for(int k=0; k<numTuples; k++) {
00365                T t(atomExt[j].id, &allTuples[k], tupleValues);
00366            #else
00367            /* get list of all tuples for the atom */
00368            int32 *curTuple = tuplesByAtom[atomExt[j].id];
00369            for( ; *curTuple != -1; ++curTuple) {             
00370              T t(&tupleStructs[*curTuple],tupleValues);
00371            #endif            
00372              register int i;
00373              aid[0] = atomMap->localID(t.atomID[0]);
00374              int homepatch = aid[0].pid;
00375              int samepatch = 1;
00376              int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]);
00377              for (i=1; i < T::size; i++) {
00378                  aid[i] = atomMap->localID(t.atomID[i]);
00379                  samepatch = samepatch && ( homepatch == aid[i].pid );
00380                  has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]);
00381              }
00382              if ( samepatch ) continue;
00383              t.scale = has_les ? invLesFactor : 1;
00384              for (i=1; i < T::size; i++) {
00385                  homepatch = patchMap->downstream(homepatch,aid[i].pid);
00386              }
00387              if ( homepatch != notUsed && isBasePatch[homepatch] ) {
00388                TuplePatchElem *p;
00389                for (i=0; i < T::size; i++) {
00390                  t.p[i] = p = tuplePatchList.find(TuplePatchElem(aid[i].pid));
00391                  if ( ! p ) {
00392                      #ifdef MEM_OPT_VERSION
00393                      iout << iWARN << "Tuple with atoms ";
00394                      #else
00395                    iout << iWARN << "Tuple " << *curTuple << " with atoms ";
00396                      #endif
00397                    int erri;
00398                    for( erri = 0; erri < T::size; erri++ ) {
00399                      iout << t.atomID[erri] << "(" <<  aid[erri].pid << ") ";
00400                    }
00401                    iout << "missing patch " << aid[i].pid << "\n" << endi;
00402                    break;
00403                  }
00404                  t.localIndex[i] = aid[i].index;
00405                }
00406                if ( ! p ) continue;
00407              #ifdef MEM_OPT_VERSION
00408                //avoid adding Tuples whose atoms are all fixed
00409                if(node->simParameters->fixedAtomsOn &&
00410                   !node->simParameters->fixedAtomsForces) {
00411                  int allfixed = 1;
00412                  for(i=0; i<T::size; i++){
00413                    CompAtomExt *one = &(t.p[i]->xExt[aid[i].index]);
00414                    allfixed = allfixed & one->atomFixed;
00415                  }
00416                  if(!allfixed) tupleList.add(t);
00417                }else{
00418                  tupleList.add(t);
00419                }
00420              #else
00421                tupleList.add(t);
00422              #endif               
00423              }
00424            }
00425         }
00426       }
00427     }


Member Data Documentation

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::accelMDdoDihe [protected]

Definition at line 445 of file ComputeHomeTuples.h.

template<class T, class S, class P>
AtomMap* ComputeHomeTuples< T, S, P >::atomMap [protected]

Definition at line 443 of file ComputeHomeTuples.h.

Referenced by ComputeHomeTuples< AnisoElem, aniso, aniso >::loadTuples().

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::doLoadTuples [protected]

Definition at line 430 of file ComputeHomeTuples.h.

template<class T, class S, class P>
char* ComputeHomeTuples< T, S, P >::isBasePatch [protected]

Definition at line 449 of file ComputeHomeTuples.h.

template<class T, class S, class P>
PatchMap* ComputeHomeTuples< T, S, P >::patchMap [protected]

Definition at line 442 of file ComputeHomeTuples.h.

Referenced by ComputeHomeTuples< AnisoElem, aniso, aniso >::loadTuples().

template<class T, class S, class P>
BigReal* ComputeHomeTuples< T, S, P >::pressureProfileData [protected]

Definition at line 447 of file ComputeHomeTuples.h.

template<class T, class S, class P>
SubmitReduction* ComputeHomeTuples< T, S, P >::pressureProfileReduction [protected]

Definition at line 446 of file ComputeHomeTuples.h.

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::pressureProfileSlabs [protected]

Definition at line 448 of file ComputeHomeTuples.h.

template<class T, class S, class P>
SubmitReduction* ComputeHomeTuples< T, S, P >::reduction [protected]

Definition at line 444 of file ComputeHomeTuples.h.

template<class T, class S, class P>
ResizeArray<T> ComputeHomeTuples< T, S, P >::tupleList [protected]

Definition at line 438 of file ComputeHomeTuples.h.

Referenced by ComputeHomeTuples< AnisoElem, aniso, aniso >::loadTuples().

template<class T, class S, class P>
TuplePatchList ComputeHomeTuples< T, S, P >::tuplePatchList [protected]

Definition at line 439 of file ComputeHomeTuples.h.

Referenced by ComputeHomeTuples< AnisoElem, aniso, aniso >::loadTuples().


The documentation for this class was generated from the following file:
Generated on Wed Nov 22 01:17:19 2017 for NAMD by  doxygen 1.4.7