00001
00007 #ifndef COMPUTESELFTUPLES_H
00008 #define COMPUTESELFTUPLES_H
00009
00010 #include "ComputeHomeTuples.h"
00011 #include "LdbCoordinator.h"
00012
00013 template <class T, class S, class P> class ComputeSelfTuples :
00014 public ComputeHomeTuples<T,S,P> {
00015
00016 private:
00017
00018 virtual void loadTuples(void) {
00019 int numTuples;
00020
00021 #ifdef MEM_OPT_VERSION
00022 AtomSignature *allSigs;
00023 #else
00024 int32 **tuplesByAtom;
00025 S *tupleStructs;
00026 #endif
00027
00028 const P *tupleValues;
00029 Node *node = Node::Object();
00030
00031 #ifdef MEM_OPT_VERSION
00032 allSigs = node->molecule->atomSigPool;
00033 #else
00034 T::getMoleculePointers(node->molecule,
00035 &numTuples, &tuplesByAtom, &tupleStructs);
00036 #endif
00037
00038 T::getParameterPointers(node->parameters, &tupleValues);
00039
00040 this->tupleList.resize(0);
00041
00042 LocalID aid[T::size];
00043
00044 const int lesOn = node->simParameters->lesOn;
00045 Real invLesFactor = lesOn ?
00046 1.0/node->simParameters->lesFactor :
00047 1.0;
00048
00049
00050
00051 TuplePatchListIter ai(this->tuplePatchList);
00052
00053 for ( ai = ai.begin(); ai != ai.end(); ai++ )
00054 {
00055
00056 CompAtom *atom = (*ai).x;
00057 Patch *patch = (*ai).p;
00058 int numAtoms = patch->getNumAtoms();
00059 #ifdef MEM_OPT_VERSION
00060 CompAtomExt *atomExt = (*ai).xExt;
00061 #endif
00062
00063
00064 for (int j=0; j < numAtoms; j++)
00065 {
00066 #ifdef MEM_OPT_VERSION
00067 AtomSignature *thisAtomSig = &allSigs[atomExt[j].sigId];
00068 TupleSignature *allTuples;
00069 T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00070 for(int k=0; k<numTuples; k++) {
00071 T t(atom[j].id, &allTuples[k], tupleValues);
00072 #else
00073
00074 int32 *curTuple = tuplesByAtom[atom[j].id];
00075
00076 for( ; *curTuple != -1; ++curTuple) {
00077 T t(&tupleStructs[*curTuple],tupleValues);
00078 #endif
00079 register int i;
00080 aid[0] = this->atomMap->localID(t.atomID[0]);
00081 int homepatch = aid[0].pid;
00082 int samepatch = 1;
00083 int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]);
00084 for (i=1; i < T::size; i++) {
00085 aid[i] = this->atomMap->localID(t.atomID[i]);
00086 samepatch = samepatch && ( homepatch == aid[i].pid );
00087 has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]);
00088 }
00089 if ( samepatch ) {
00090 t.scale = has_les ? invLesFactor : 1;
00091 TuplePatchElem *p;
00092 p = this->tuplePatchList.find(TuplePatchElem(homepatch));
00093 for (i=0; i < T::size; i++) {
00094 t.p[i] = p;
00095 t.localIndex[i] = aid[i].index;
00096 }
00097 this->tupleList.add(t);
00098 }
00099 }
00100 }
00101 }
00102 }
00103
00104 PatchID patchID;
00105
00106 public:
00107
00108 ComputeSelfTuples(ComputeID c, PatchID p) : ComputeHomeTuples<T,S,P>(c) {
00109 patchID = p;
00110 }
00111
00112 virtual ~ComputeSelfTuples() {
00113 UniqueSetIter<TuplePatchElem> ap(this->tuplePatchList);
00114 for (ap = ap.begin(); ap != ap.end(); ap++) {
00115 ap->p->unregisterPositionPickup(this->cid,&(ap->positionBox));
00116 ap->p->unregisterAvgPositionPickup(this->cid,&(ap->avgPositionBox));
00117 ap->p->unregisterForceDeposit(this->cid,&(ap->forceBox));
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126 virtual void initialize(void) {
00127
00128
00129 this->tuplePatchList.clear();
00130
00131 this->tuplePatchList.add(TuplePatchElem(ComputeHomeTuples<T,S,P>::patchMap->patch(patchID), this->cid));
00132
00133 setNumPatches(this->tuplePatchList.size());
00134 this->doLoadTuples = true;
00135
00136 int myNode = CkMyPe();
00137 if ( PatchMap::Object()->node(patchID) != myNode )
00138 {
00139 this->basePriority = COMPUTE_PROXY_PRIORITY + PATCH_PRIORITY(patchID);
00140 }
00141 else
00142 {
00143 this->basePriority = COMPUTE_HOME_PRIORITY + PATCH_PRIORITY(patchID);
00144 }
00145 }
00146
00147 void doWork(void) {
00148 LdbCoordinator::Object()->startWork(this->cid,0);
00149
00150 #ifdef TRACE_COMPUTE_OBJECTS
00151 double traceObjStartTime = CmiWallTimer();
00152 #endif
00153
00154 ComputeHomeTuples<T,S,P>::doWork();
00155
00156 #ifdef TRACE_COMPUTE_OBJECTS
00157 traceUserBracketEvent(TRACE_COMPOBJ_IDOFFSET+this->cid, traceObjStartTime, CmiWallTimer());
00158 #endif
00159
00160 LdbCoordinator::Object()->endWork(this->cid,0);
00161 }
00162
00163 };
00164
00165
00166 #endif
00167