00001
00007 #ifndef REDUCTIONMGR_H
00008 #define REDUCTIONMGR_H
00009
00010 #include "charm++.h"
00011
00012 #include "main.h"
00013 #include "NamdTypes.h"
00014 #include "BOCgroup.h"
00015 #include "ProcessorPrivate.h"
00016
00017 #define VECTOR(A) A ## _X, A ## _Y, A ## _Z
00018 #define TENSOR(A) A ## _XX, A ## _XY, A ## _XZ, \
00019 A ## _YX, A ## _YY, A ## _YZ, \
00020 A ## _ZX, A ## _ZY, A ## _ZZ
00021
00022 #define ADD_VECTOR(R,RL,D,DL) \
00023 R->item( RL ## _X ) += D[ DL ## _X ]; \
00024 R->item( RL ## _Y ) += D[ DL ## _Y ]; \
00025 R->item( RL ## _Z ) += D[ DL ## _Z ]
00026
00027 #define ADD_VECTOR_OBJECT(R,RL,D) \
00028 R->item( RL ## _X ) += D.x; \
00029 R->item( RL ## _Y ) += D.y; \
00030 R->item( RL ## _Z ) += D.z
00031
00032 #define ADD_TENSOR(R,RL,D,DL) \
00033 R->item( RL ## _XX) += D[ DL ## _XX ]; \
00034 R->item( RL ## _XY) += D[ DL ## _XY ]; \
00035 R->item( RL ## _XZ) += D[ DL ## _XZ ]; \
00036 R->item( RL ## _YX) += D[ DL ## _YX ]; \
00037 R->item( RL ## _YY) += D[ DL ## _YY ]; \
00038 R->item( RL ## _YZ) += D[ DL ## _YZ ]; \
00039 R->item( RL ## _ZX) += D[ DL ## _ZX ]; \
00040 R->item( RL ## _ZY) += D[ DL ## _ZY ]; \
00041 R->item( RL ## _ZZ) += D[ DL ## _ZZ ]
00042
00043 #define ADD_TENSOR_OBJECT(R,RL,D) \
00044 R->item( RL ## _XX) += D.xx; \
00045 R->item( RL ## _XY) += D.xy; \
00046 R->item( RL ## _XZ) += D.xz; \
00047 R->item( RL ## _YX) += D.yx; \
00048 R->item( RL ## _YY) += D.yy; \
00049 R->item( RL ## _YZ) += D.yz; \
00050 R->item( RL ## _ZX) += D.zx; \
00051 R->item( RL ## _ZY) += D.zy; \
00052 R->item( RL ## _ZZ) += D.zz
00053
00054 #define GET_VECTOR(O,R,A) \
00055 O.x = R->item( A ## _X ); \
00056 O.y = R->item( A ## _Y ); \
00057 O.z = R->item( A ## _Z )
00058
00059 #define GET_TENSOR(O,R,A) \
00060 O.xx = R->item( A ## _XX); \
00061 O.xy = R->item( A ## _XY); \
00062 O.xz = R->item( A ## _XZ); \
00063 O.yx = R->item( A ## _YX); \
00064 O.yy = R->item( A ## _YY); \
00065 O.yz = R->item( A ## _YZ); \
00066 O.zx = R->item( A ## _ZX); \
00067 O.zy = R->item( A ## _ZY); \
00068 O.zz = R->item( A ## _ZZ)
00069
00070 typedef enum
00071 {
00072
00073 REDUCTION_ANGLE_ENERGY,
00074 REDUCTION_BOND_ENERGY,
00075 REDUCTION_DIHEDRAL_ENERGY,
00076 REDUCTION_ELECT_ENERGY,
00077 REDUCTION_ELECT_ENERGY_F,
00078 REDUCTION_ELECT_ENERGY_TI_1,
00079 REDUCTION_ELECT_ENERGY_TI_2,
00080 REDUCTION_ELECT_ENERGY_SLOW,
00081 REDUCTION_ELECT_ENERGY_SLOW_F,
00082 REDUCTION_ELECT_ENERGY_SLOW_TI_1,
00083 REDUCTION_ELECT_ENERGY_SLOW_TI_2,
00084 REDUCTION_ELECT_ENERGY_PME_TI_1,
00085 REDUCTION_ELECT_ENERGY_PME_TI_2,
00086 REDUCTION_IMPROPER_ENERGY,
00087 REDUCTION_CROSSTERM_ENERGY,
00088 REDUCTION_HALFSTEP_KINETIC_ENERGY,
00089 REDUCTION_CENTERED_KINETIC_ENERGY,
00090 REDUCTION_INT_HALFSTEP_KINETIC_ENERGY,
00091 REDUCTION_INT_CENTERED_KINETIC_ENERGY,
00092 REDUCTION_DRUDECOM_CENTERED_KINETIC_ENERGY,
00093 REDUCTION_DRUDEBOND_CENTERED_KINETIC_ENERGY,
00094 REDUCTION_LJ_ENERGY,
00095 REDUCTION_LJ_ENERGY_F,
00096 REDUCTION_LJ_ENERGY_TI_1,
00097 REDUCTION_LJ_ENERGY_TI_2,
00098 REDUCTION_BC_ENERGY,
00099 REDUCTION_SMD_ENERGY,
00100 REDUCTION_MISC_ENERGY,
00101
00102 TENSOR(REDUCTION_VIRIAL_NORMAL),
00103 TENSOR(REDUCTION_VIRIAL_NBOND),
00104 TENSOR(REDUCTION_VIRIAL_SLOW),
00105 #ifdef ALTVIRIAL
00106 TENSOR(REDUCTION_ALT_VIRIAL_NORMAL),
00107 TENSOR(REDUCTION_ALT_VIRIAL_NBOND),
00108 TENSOR(REDUCTION_ALT_VIRIAL_SLOW),
00109 #endif
00110 TENSOR(REDUCTION_INT_VIRIAL_NORMAL),
00111 TENSOR(REDUCTION_INT_VIRIAL_NBOND),
00112 TENSOR(REDUCTION_INT_VIRIAL_SLOW),
00113 VECTOR(REDUCTION_EXT_FORCE_NORMAL),
00114 VECTOR(REDUCTION_EXT_FORCE_NBOND),
00115 VECTOR(REDUCTION_EXT_FORCE_SLOW),
00116
00117 VECTOR(REDUCTION_MOMENTUM),
00118 VECTOR(REDUCTION_ANGULAR_MOMENTUM),
00119 VECTOR(REDUCTION_HALFSTEP_MOMENTUM),
00120 REDUCTION_MOMENTUM_MASS,
00121
00122 REDUCTION_MIN_F_DOT_F,
00123 REDUCTION_MIN_F_DOT_V,
00124 REDUCTION_MIN_V_DOT_V,
00125 REDUCTION_MIN_HUGE_COUNT,
00126
00127 VECTOR(REDUCTION_PAIR_VDW_FORCE),
00128 VECTOR(REDUCTION_PAIR_ELECT_FORCE),
00129
00130 REDUCTION_ATOM_CHECKSUM,
00131 REDUCTION_COMPUTE_CHECKSUM,
00132 REDUCTION_BOND_CHECKSUM,
00133 REDUCTION_ANGLE_CHECKSUM,
00134 REDUCTION_DIHEDRAL_CHECKSUM,
00135 REDUCTION_IMPROPER_CHECKSUM,
00136 REDUCTION_CROSSTERM_CHECKSUM,
00137 REDUCTION_EXCLUSION_CHECKSUM,
00138 REDUCTION_MARGIN_VIOLATIONS,
00139 REDUCTION_PAIRLIST_WARNINGS,
00140 REDUCTION_STRAY_CHARGE_ERRORS,
00141
00142 REDUCTION_MAX_RESERVED
00143 } ReductionTag;
00144
00145
00146 enum {
00147 REDUCTIONS_BASIC,
00148 REDUCTIONS_PPROF_BONDED,
00149 REDUCTIONS_PPROF_NONBONDED,
00150 REDUCTIONS_PPROF_INTERNAL,
00151 REDUCTIONS_PPROF_KINETIC,
00152 REDUCTIONS_USER1,
00153 REDUCTIONS_USER2,
00154
00155 REDUCTION_MAX_SET_ID
00156 };
00157
00158
00159 #define REDUCTION_MAX_CHILDREN 4
00160
00161 class ReductionRegisterMsg;
00162 class ReductionSubmitMsg;
00163 class SubmitReduction;
00164 class RequireReduction;
00165
00166
00167 class ReductionSetData {
00168 public:
00169 int sequenceNumber;
00170 int submitsRecorded;
00171 BigReal *data;
00172 ReductionSetData *next;
00173 ReductionSetData(int seqNum, int size) {
00174 sequenceNumber = seqNum;
00175 submitsRecorded = 0;
00176 data = new BigReal[size];
00177 for ( int i = 0; i < size; ++i ) { data[i] = 0; }
00178 next = 0;
00179 }
00180 ~ReductionSetData() {
00181 delete [] data;
00182 }
00183 };
00184
00185
00186 class ReductionSet {
00187 public:
00188 int reductionSetID;
00189 int nextSequenceNumber;
00190 int submitsRegistered;
00191 int dataSize;
00192 ReductionSetData *dataQueue;
00193 ReductionSetData* getData(int seqNum);
00194 ReductionSetData* removeData(int seqNum);
00195 int requireRegistered;
00196 int threadIsWaiting;
00197 int waitingForSequenceNumber;
00198 CthThread waitingThread;
00199 ReductionSet(int setID, int size,int numChildren);
00200 ~ReductionSet();
00201 int *addToRemoteSequenceNumber;
00202 };
00203
00204
00205 class ReductionMgr : public BOCclass
00206 {
00207 private:
00208 friend class SubmitReduction;
00209 friend class RequireReduction;
00210
00211 ReductionSet * (reductionSets[REDUCTION_MAX_SET_ID]);
00212
00213 int myParent;
00214 #if 0
00215 int firstChild, lastChild;
00216 int isMyChild(int nodeID) const {
00217 return ( nodeID >= firstChild && nodeID < lastChild );
00218 }
00219 #endif
00220 int numChildren;
00221 int *children;
00222 int isMyChild(int nodeID) const {
00223 int i;
00224 for(i=0;i<numChildren;i++)
00225 if (children[i]==nodeID) return 1;
00226 return 0;
00227 }
00228 int childIndex(int nodeID) const {
00229 int i;
00230 for(i=0;i<numChildren;i++)
00231 if (children[i]==nodeID) return i;
00232 return -1;
00233 }
00234 int isRoot(void) const { return ( myParent == -1 ); }
00235
00236 ReductionSet* getSet(int setID, int size);
00237 void delSet(int setID);
00238
00239 void mergeAndDeliver(ReductionSet *set, int seqNum);
00240
00241 void submit(SubmitReduction*);
00242 void remove(SubmitReduction*);
00243
00244 void require(RequireReduction*);
00245 void remove(RequireReduction*);
00246
00247 public:
00248
00249
00250 inline static ReductionMgr *Object(void) {
00251 return CkpvAccess(ReductionMgr_instance);
00252 }
00253
00254 ReductionMgr();
00255 ~ReductionMgr();
00256
00257 void buildSpanTree(const int pe,
00258 const int max_intranode_children,
00259 const int max_internode_children,
00260 int* parent,
00261 int* num_children,
00262 int** children);
00263
00264
00265 SubmitReduction* willSubmit(int setID, int size = -1);
00266 RequireReduction* willRequire(int setID, int size = -1);
00267
00268
00269 void remoteRegister(ReductionRegisterMsg *msg);
00270 void remoteUnregister(ReductionRegisterMsg *msg);
00271 void remoteSubmit(ReductionSubmitMsg *msg);
00272
00273 };
00274
00275
00276 class SubmitReduction {
00277 private:
00278 friend class ReductionMgr;
00279 int reductionSetID;
00280 int sequenceNumber;
00281 ReductionMgr *master;
00282 BigReal *data;
00283 public:
00284 inline BigReal& item(int i) {
00285 return data[i];
00286 }
00287 void add(int nitems, const BigReal *arr) {
00288 for (int i=0; i<nitems; i++) data[i] += arr[i];
00289 }
00290 void submit(void) {
00291 master->submit(this);
00292 }
00293 ~SubmitReduction(void) { master->remove(this); }
00294 };
00295
00296
00297 class RequireReduction {
00298 private:
00299 friend class ReductionMgr;
00300 int reductionSetID;
00301 int sequenceNumber;
00302 ReductionMgr *master;
00303 ReductionSetData *currentData;
00304 BigReal *data;
00305 RequireReduction(void) { currentData = 0; data = 0; }
00306 public:
00307 BigReal item(int i) const { return data[i]; }
00308 void require(void) {
00309 master->require(this);
00310 }
00311 ~RequireReduction(void) { delete currentData; master->remove(this); }
00312 };
00313
00314
00315 #endif
00316