version 1.26 | version 1.27 |
---|
| |
#include "ComputeHomeTuples.h" | #include "ComputeHomeTuples.h" |
#include "LdbCoordinator.h" | #include "LdbCoordinator.h" |
| |
| #ifdef USE_HOMETUPLES |
| template <class T, class S, class P> class SelfTuples : public HomeTuples<T, S, P> { |
| |
| public: |
| SelfTuples(int type=-1) : HomeTuples<T,S,P>(type) {} |
| |
| private: |
| |
| virtual void loadTuples(TuplePatchList& tuplePatchList, const char* isBasePatch, AtomMap *atomMap, |
| const std::vector<int>& pids = std::vector<int>()) { |
| |
| if (isBasePatch != NULL) { |
| iout << iWARN << "Non-NULL isBasePatch detected in SelfTuples::loadTuples()" << endi; |
| } |
| |
| int numTuples; |
| |
| #ifdef MEM_OPT_VERSION |
| typename ElemTraits<T>::signature *allSigs; |
| #else |
| int32 **tuplesByAtom; |
| /* const (need to propagate const) */ S *tupleStructs; |
| #endif |
| |
| const P *tupleValues; |
| Node *node = Node::Object(); |
| PatchMap *patchMap = PatchMap::Object(); |
| // AtomMap *atomMap = AtomMap::Object(); |
| |
| #ifdef MEM_OPT_VERSION |
| allSigs = ElemTraits<T>::get_sig_pointer(node->molecule); |
| #else |
| T::getMoleculePointers(node->molecule, |
| &numTuples, &tuplesByAtom, &tupleStructs); |
| #endif |
| |
| T::getParameterPointers(node->parameters, &tupleValues); |
| |
| this->tupleList.clear(); |
| |
| LocalID aid[T::size]; |
| |
| const int lesOn = node->simParameters->lesOn; |
| Real invLesFactor = lesOn ? |
| 1.0/node->simParameters->lesFactor : |
| 1.0; |
| |
| // cycle through each patch and gather all tuples |
| // There should be only one! |
| TuplePatchListIter ai(tuplePatchList); |
| if (pids.size() == 0) ai = ai.begin(); |
| |
| int numPid = (pids.size() == 0) ? tuplePatchList.size() : pids.size(); |
| |
| for (int ipid=0;ipid < numPid;ipid++) { |
| Patch *patch; |
| int numAtoms; |
| CompAtomExt *atomExt; |
| // Take next patch |
| if (pids.size() == 0) { |
| patch = (*ai).p; |
| numAtoms = patch->getNumAtoms(); |
| atomExt = (*ai).xExt; |
| ai++; |
| } else { |
| TuplePatchElem *tpe = tuplePatchList.find(TuplePatchElem(pids[ipid])); |
| patch = tpe->p; |
| numAtoms = patch->getNumAtoms(); |
| atomExt = tpe->xExt; |
| } |
| |
| // cycle through each atom in the patch and load up tuples |
| for (int j=0; j < numAtoms; j++) |
| { |
| #ifdef MEM_OPT_VERSION |
| typename ElemTraits<T>::signature *thisAtomSig = |
| &allSigs[ElemTraits<T>::get_sig_id(atomExt[j])]; |
| TupleSignature *allTuples; |
| T::getTupleInfo(thisAtomSig, &numTuples, &allTuples); |
| for(int k=0; k<numTuples; k++) { |
| T t(atomExt[j].id, &allTuples[k], tupleValues); |
| #else |
| /* get list of all tuples for the atom */ |
| int32 *curTuple = tuplesByAtom[atomExt[j].id]; |
| /* cycle through each tuple */ |
| for( ; *curTuple != -1; ++curTuple) { |
| T t(&tupleStructs[*curTuple],tupleValues); |
| #endif |
| register int i; |
| aid[0] = atomMap->localID(t.atomID[0]); |
| int homepatch = aid[0].pid; |
| int samepatch = 1; |
| int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]); |
| for (i=1; i < T::size; i++) { |
| aid[i] = atomMap->localID(t.atomID[i]); |
| samepatch = samepatch && ( homepatch == aid[i].pid ); |
| has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]); |
| } |
| if ( samepatch ) { |
| t.scale = has_les ? invLesFactor : 1; |
| TuplePatchElem *p; |
| p = tuplePatchList.find(TuplePatchElem(homepatch)); |
| for(i=0; i < T::size; i++) { |
| t.p[i] = p; |
| t.localIndex[i] = aid[i].index; |
| } |
| #ifdef MEM_OPT_VERSION |
| //avoid adding Tuples whose atoms are all fixed |
| if(node->simParameters->fixedAtomsOn && |
| !node->simParameters->fixedAtomsForces) { |
| int allfixed = 1; |
| for(i=0; i<T::size; i++){ |
| CompAtomExt *one = &(p->xExt[aid[i].index]); |
| allfixed = allfixed & one->atomFixed; |
| } |
| if(!allfixed) this->tupleList.push_back(t); |
| } else { |
| this->tupleList.push_back(t); |
| } |
| #else |
| this->tupleList.push_back(t); |
| #endif |
| } |
| } |
| } |
| } |
| } |
| |
| }; |
| #endif |
| |
template <class T, class S, class P> class ComputeSelfTuples : | template <class T, class S, class P> class ComputeSelfTuples : |
public ComputeHomeTuples<T,S,P> { | public ComputeHomeTuples<T,S,P> { |
| |
| #ifndef USE_HOMETUPLES |
private: | private: |
| |
virtual void loadTuples(void) { | virtual void loadTuples(void) { |
| |
} | } |
} | } |
} | } |
| #endif |
| |
PatchID patchID; | PatchID patchID; |
| |
| |
// atom maps, patchmaps etc are ready and we are about to start computations | // atom maps, patchmaps etc are ready and we are about to start computations |
//====================================================================== | //====================================================================== |
virtual void initialize(void) { | virtual void initialize(void) { |
| #ifdef USE_HOMETUPLES |
| this->tuples = new SelfTuples<T, S, P>(); |
| #endif |
// Start with empty list | // Start with empty list |
this->tuplePatchList.clear(); | this->tuplePatchList.clear(); |
| |
this->tuplePatchList.add(TuplePatchElem(ComputeHomeTuples<T,S,P>::patchMap->patch(patchID), this)); | this->tuplePatchList.add(TuplePatchElem(ComputeHomeTuples<T,S,P>::patchMap->patch(patchID), this)); |
| |
this->setNumPatches(this->tuplePatchList.size()); | this->setNumPatches(this->tuplePatchList.size()); |
| |
this->doLoadTuples = true; | this->doLoadTuples = true; |
| |
int myNode = CkMyPe(); | int myNode = CkMyPe(); |