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

Generated on Tue Sep 19 01:17:11 2017 for NAMD by  doxygen 1.4.7