ComputeSelfTuples.h

Go to the documentation of this file.
00001 
00007 #ifndef COMPUTESELFTUPLES_H
00008 #define COMPUTESELFTUPLES_H
00009 
00010 #include "ComputeHomeTuples.h"
00011 #include "LdbCoordinator.h"
00012 
00013 #ifdef USE_HOMETUPLES
00014 template <class T, class S, class P> class SelfTuples : public HomeTuples<T, S, P> {
00015 
00016   public:
00017     SelfTuples(int type=-1) : HomeTuples<T,S,P>(type) {}
00018 
00019   private:
00020 
00021     virtual void loadTuples(TuplePatchList& tuplePatchList, const char* isBasePatch, AtomMap *atomMap,
00022       const std::vector<int>& pids = std::vector<int>()) {
00023 
00024       if (isBasePatch != NULL) {
00025         iout << iWARN << "Non-NULL isBasePatch detected in SelfTuples::loadTuples()" << endi;
00026       }
00027 
00028       int numTuples;
00029 
00030       #ifdef MEM_OPT_VERSION
00031       typename ElemTraits<T>::signature *allSigs;
00032       #else
00033       int32 **tuplesByAtom;
00034       /* const (need to propagate const) */ S *tupleStructs;
00035       #endif
00036 
00037       const P *tupleValues;
00038       Node *node = Node::Object();
00039       PatchMap *patchMap = PatchMap::Object();
00040       // AtomMap *atomMap = AtomMap::Object();
00041 
00042       #ifdef MEM_OPT_VERSION
00043       allSigs = ElemTraits<T>::get_sig_pointer(node->molecule);
00044       #else
00045       T::getMoleculePointers(node->molecule,
00046         &numTuples, &tuplesByAtom, &tupleStructs);
00047       #endif
00048       
00049       T::getParameterPointers(node->parameters, &tupleValues);
00050 
00051       this->tupleList.clear();
00052 
00053       LocalID aid[T::size];
00054 
00055       const int lesOn = node->simParameters->lesOn;
00056       const int soluteScalingOn = node->simParameters->soluteScalingOn;
00057       Real invLesFactor = lesOn ?
00058                           1.0/node->simParameters->lesFactor :
00059                           1.0;
00060       const Real soluteScalingFactor = node->simParameters->soluteScalingFactor;
00061       const Bool soluteScalingAll = node->simParameters->soluteScalingAll;
00062 
00063       // cycle through each patch and gather all tuples
00064       // There should be only one!
00065       TuplePatchListIter ai(tuplePatchList);
00066       if (pids.size() == 0) ai = ai.begin();
00067 
00068       int numPid = (pids.size() == 0) ? tuplePatchList.size() : pids.size();
00069 
00070       for (int ipid=0;ipid < numPid;ipid++) {
00071         Patch *patch;
00072         int numAtoms;
00073         CompAtomExt *atomExt;
00074         // Take next patch
00075         if (pids.size() == 0) {
00076           patch = (*ai).p;
00077           numAtoms = patch->getNumAtoms();
00078           atomExt = (*ai).xExt;
00079           ai++;
00080         } else {
00081           TuplePatchElem *tpe = tuplePatchList.find(TuplePatchElem(pids[ipid]));
00082           patch = tpe->p;
00083           numAtoms = patch->getNumAtoms();
00084           atomExt = tpe->xExt;          
00085         }
00086   
00087         // cycle through each atom in the patch and load up tuples
00088         for (int j=0; j < numAtoms; j++)
00089         {
00090 #ifdef MEM_OPT_VERSION
00091           typename ElemTraits<T>::signature *thisAtomSig =
00092                    &allSigs[ElemTraits<T>::get_sig_id(atomExt[j])];
00093           TupleSignature *allTuples;
00094           T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00095           for(int k=0; k<numTuples; k++) {
00096             T t(atomExt[j].id, &allTuples[k], tupleValues);
00097 #else
00098           /* get list of all tuples for the atom */
00099           int32 *curTuple = tuplesByAtom[atomExt[j].id];    
00100           /* cycle through each tuple */
00101           for( ; *curTuple != -1; ++curTuple) {
00102             T t(&tupleStructs[*curTuple],tupleValues);
00103 #endif
00104             register int i;
00105             aid[0] = atomMap->localID(t.atomID[0]);
00106             int homepatch = aid[0].pid;
00107             int samepatch = 1;
00108             int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]);
00109              int has_ss = soluteScalingOn && node->molecule->get_ss_type(t.atomID[0]);
00110             for (i=1; i < T::size; i++) {
00111               aid[i] = atomMap->localID(t.atomID[i]);
00112               samepatch = samepatch && ( homepatch == aid[i].pid );
00113               has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]);
00114               has_ss |= soluteScalingOn && node->molecule->get_ss_type(t.atomID[i]);
00115             }
00116             if (T::size < 4 && !soluteScalingAll) has_ss = false;
00117             if ( samepatch ) {
00118               t.scale = (!has_les && !has_ss) ? 1.0 : ( has_les ? invLesFactor : soluteScalingFactor );
00119               TuplePatchElem *p;
00120               p = tuplePatchList.find(TuplePatchElem(homepatch));
00121               for(i=0; i < T::size; i++) {
00122                 t.p[i] = p;
00123                 t.localIndex[i] = aid[i].index;
00124               }
00125 #ifdef MEM_OPT_VERSION
00126               //avoid adding Tuples whose atoms are all fixed
00127               if(node->simParameters->fixedAtomsOn &&
00128                  !node->simParameters->fixedAtomsForces) {
00129                 int allfixed = 1;
00130                 for(i=0; i<T::size; i++){
00131                   CompAtomExt *one = &(p->xExt[aid[i].index]);
00132                   allfixed = allfixed & one->atomFixed;
00133                 }
00134                 if(!allfixed) this->tupleList.push_back(t);
00135               } else {
00136                 this->tupleList.push_back(t);
00137               }
00138 #else
00139               this->tupleList.push_back(t);
00140 #endif
00141             }
00142           }
00143         }
00144       }
00145     }
00146 
00147 };
00148 #endif
00149 
00150 template <class T, class S, class P> class ComputeSelfTuples :
00151         public ComputeHomeTuples<T,S,P> {
00152 
00153 #ifndef USE_HOMETUPLES
00154   private:
00155   
00156     virtual void loadTuples(void) {
00157       int numTuples;
00158 
00159       #ifdef MEM_OPT_VERSION
00160       typename ElemTraits<T>::signature *allSigs;
00161       #else
00162       int32 **tuplesByAtom;
00163       /* const (need to propagate const) */ S *tupleStructs;
00164       #endif
00165 
00166       const P *tupleValues;
00167       Node *node = Node::Object();
00168 
00169       #ifdef MEM_OPT_VERSION
00170       allSigs = ElemTraits<T>::get_sig_pointer(node->molecule);
00171       #else
00172       T::getMoleculePointers(node->molecule,
00173                     &numTuples, &tuplesByAtom, &tupleStructs);
00174       #endif
00175       
00176       T::getParameterPointers(node->parameters, &tupleValues);
00177 
00178       this->tupleList.resize(0);
00179 
00180       LocalID aid[T::size];
00181 
00182       const int lesOn = node->simParameters->lesOn;
00183       const int soluteScalingOn = node->simParameters->soluteScalingOn;
00184       Real invLesFactor = lesOn ?
00185                           1.0/node->simParameters->lesFactor :
00186                           1.0;
00187       const Real soluteScalingFactor = node->simParameters->soluteScalingFactor;
00188       const Bool soluteScalingAll = node->simParameters->soluteScalingAll;
00189 
00190       // cycle through each patch and gather all tuples
00191       // There should be only one!
00192       TuplePatchListIter ai(this->tuplePatchList);
00193 
00194       for ( ai = ai.begin(); ai != ai.end(); ai++ )
00195       {
00196     
00197         // CompAtomExt *atom = (*ai).x;
00198         Patch *patch = (*ai).p;
00199         int numAtoms = patch->getNumAtoms();
00200         CompAtomExt *atomExt = (*ai).xExt; //patch->getCompAtomExtInfo();
00201     
00202         // cycle through each atom in the patch and load up tuples
00203         for (int j=0; j < numAtoms; j++)
00204         {
00205            #ifdef MEM_OPT_VERSION
00206            typename ElemTraits<T>::signature *thisAtomSig =
00207                    &allSigs[ElemTraits<T>::get_sig_id(atomExt[j])];
00208            TupleSignature *allTuples;
00209            T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00210            for(int k=0; k<numTuples; k++) {
00211                T t(atomExt[j].id, &allTuples[k], tupleValues);
00212            #else
00213            /* get list of all tuples for the atom */
00214            int32 *curTuple = tuplesByAtom[atomExt[j].id];    
00215            /* cycle through each tuple */
00216            for( ; *curTuple != -1; ++curTuple) {
00217              T t(&tupleStructs[*curTuple],tupleValues);
00218            #endif
00219              register int i;
00220              aid[0] = this->atomMap->localID(t.atomID[0]);
00221              int homepatch = aid[0].pid;
00222              int samepatch = 1;
00223              int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]);
00224              int has_ss = soluteScalingOn && node->molecule->get_ss_type(t.atomID[0]);
00225              for (i=1; i < T::size; i++) {
00226                  aid[i] = this->atomMap->localID(t.atomID[i]);
00227                  samepatch = samepatch && ( homepatch == aid[i].pid );
00228                  has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]);
00229                  has_ss |= soluteScalingOn && node->molecule->get_ss_type(t.atomID[i]);
00230              }
00231              if (T::size < 4 && !soluteScalingAll) has_ss = false;
00232              if ( samepatch ) {
00233                t.scale = (!has_les && !has_ss) ? 1.0 : ( has_les ? invLesFactor : soluteScalingFactor );
00234                TuplePatchElem *p;
00235                p = this->tuplePatchList.find(TuplePatchElem(homepatch));
00236                for(i=0; i < T::size; i++) {
00237                    t.p[i] = p;
00238                    t.localIndex[i] = aid[i].index;
00239                }
00240              #ifdef MEM_OPT_VERSION
00241                //avoid adding Tuples whose atoms are all fixed
00242                if(node->simParameters->fixedAtomsOn &&
00243                   !node->simParameters->fixedAtomsForces) {
00244                  int allfixed = 1;
00245                  for(i=0; i<T::size; i++){
00246                    CompAtomExt *one = &(p->xExt[aid[i].index]);
00247                    allfixed = allfixed & one->atomFixed;
00248                  }
00249                  if(!allfixed) this->tupleList.add(t);
00250                }else{
00251                  this->tupleList.add(t);
00252                }
00253              #else
00254                this->tupleList.add(t);
00255              #endif               
00256              }
00257            }
00258         }
00259       }
00260     }
00261 #endif
00262 
00263     PatchID patchID;
00264 
00265   public:
00266 
00267     ComputeSelfTuples(ComputeID c, PatchID p) : ComputeHomeTuples<T,S,P>(c) {
00268       patchID = p;
00269     }
00270 
00271     virtual ~ComputeSelfTuples() {
00272       UniqueSetIter<TuplePatchElem> ap(this->tuplePatchList);
00273       for (ap = ap.begin(); ap != ap.end(); ap++) {
00274         ap->p->unregisterPositionPickup(this,&(ap->positionBox));
00275         ap->p->unregisterAvgPositionPickup(this,&(ap->avgPositionBox));
00276         ap->p->unregisterForceDeposit(this,&(ap->forceBox));
00277       }
00278     }
00279 
00280 
00281     //======================================================================
00282     // initialize() - Method is invoked only the first time
00283     // atom maps, patchmaps etc are ready and we are about to start computations
00284     //======================================================================
00285     virtual void initialize(void) {
00286 #ifdef USE_HOMETUPLES
00287       this->tuples = new SelfTuples<T, S, P>();
00288 #endif    
00289       // Start with empty list
00290       this->tuplePatchList.clear();
00291     
00292       this->tuplePatchList.add(TuplePatchElem(ComputeHomeTuples<T,S,P>::patchMap->patch(patchID), this));
00293     
00294       this->setNumPatches(this->tuplePatchList.size());
00295 
00296       this->doLoadTuples = true;
00297 
00298       int myNode = CkMyPe();
00299       if ( PatchMap::Object()->node(patchID) != myNode )
00300       {
00301         this->basePriority = COMPUTE_PROXY_PRIORITY + PATCH_PRIORITY(patchID);
00302       }
00303       else
00304       {
00305         this->basePriority = COMPUTE_HOME_PRIORITY + PATCH_PRIORITY(patchID);
00306       }
00307     }
00308 
00309     void doWork(void) {
00310 //      LdbCoordinator::Object()->startWork(this->ldObjHandle);
00311 
00312 #ifdef TRACE_COMPUTE_OBJECTS
00313     double traceObjStartTime = CmiWallTimer();
00314 #endif
00315 
00316       ComputeHomeTuples<T,S,P>::doWork();
00317 
00318 #ifdef TRACE_COMPUTE_OBJECTS
00319     traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+this->cid, traceObjStartTime, CmiWallTimer());
00320 #endif
00321 
00322 //      LdbCoordinator::Object()->endWork(this->ldObjHandle);
00323     }
00324 
00325 };
00326 
00327 
00328 #endif
00329 

Generated on Thu Jun 21 01:17:14 2018 for NAMD by  doxygen 1.4.7