PmeSolver.h

Go to the documentation of this file.
00001 #ifndef PMESOLVER_H
00002 #define PMESOLVER_H
00003 #include <vector>
00004 #include "ReductionMgr.h"
00005 #include "PatchMap.h"
00006 #include "PmeSolverUtil.h"
00007 #include "PmeSolver.decl.h"
00008 
00009 class PmePencilXYZMap : public CBase_PmePencilXYZMap {
00010 public:
00011   PmePencilXYZMap(int pe) : pe(pe) {
00012   }
00013   //PmePencilXYZMap(CkMigrateMessage *m) {}
00014   int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
00015     return 0;
00016   }
00017   virtual int procNum(int, const CkArrayIndex& idx) {
00018     return pe;
00019   }
00020   virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
00021     if (pe == CkMyPe()) {
00022       if ( ! msg ) NAMD_bug("PmePencilXYZMap::populateInitial, multiple pencils on a pe?");
00023       mgr->insertInitial(CkArrayIndex1D(0), msg);
00024       msg = NULL;
00025     }
00026     mgr->doneInserting();
00027     if (msg != NULL) CkFreeMsg(msg);
00028   }
00029 private:
00030   const int pe;
00031 };
00032 
00033 class PmePencilXMap : public CBase_PmePencilXMap {
00034 public:
00035   PmePencilXMap(int ia, int ib, int width, const std::vector<int>& pes) : ia(ia), ib(ib), width(width), pes(pes) {}
00036   int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
00037     return 0;
00038   }
00039   virtual int procNum(int, const CkArrayIndex& idx) {
00040     int ind = idx.data()[ia] + idx.data()[ib] * width;
00041     if (ind < 0 || ind >= pes.size())
00042       NAMD_bug("PmePencilXMap::procNum, index out of bounds");
00043     return pes[ind];
00044   }
00045   virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
00046     for (int i=0;i < pes.size();i++) {
00047       if (pes[i] == CkMyPe()) {
00048         if ( msg == NULL ) NAMD_bug("PmePencilXMap::populateInitial, multiple pencils on a pe?");
00049         CkArrayIndex3D ai(0,0,0);
00050         ai.data()[ib] = i / width;
00051         ai.data()[ia] = i % width;
00052         //fprintf(stderr, "Pe %d i %d at %d %d\n", pes[i], i, ai.data()[ia], ai.data()[ib]);
00053         if ( procNum(0,ai) != CkMyPe() ) NAMD_bug("PmePencilXMap::populateInitial, map is inconsistent");
00054         mgr->insertInitial(ai,msg);
00055         msg = NULL;
00056       }
00057     }
00058     mgr->doneInserting();
00059     if (msg != NULL) CkFreeMsg(msg);
00060   }
00061 private:
00062   // Index of CkArrayIndex data()
00063   const int ia, ib;
00064   // Width of the 2D array in pes
00065   const int width;
00066   // List of Pes. Index is given by pes[i + j*width]
00067   const std::vector<int> pes;
00068 };
00069 
00070 class PmePencilXYMap : public CBase_PmePencilXYMap {
00071 public:
00072   PmePencilXYMap(const std::vector<int>& pes) : pes(pes) {}
00073   int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
00074     return 0;
00075   }
00076   virtual int procNum(int, const CkArrayIndex& idx) {
00077     int ind = idx.data()[2];
00078     if (ind < 0 || ind >= pes.size())
00079       NAMD_bug("PmePencilXYMap::procNum, index out of bounds");
00080     return pes[ind];
00081   }
00082   virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
00083     for (int i=0;i < pes.size();i++) {
00084       if (pes[i] == CkMyPe()) {
00085         if ( msg == NULL ) NAMD_bug("PmePencilXYMap::populateInitial, multiple pencils on a pe?");
00086         CkArrayIndex3D ai(0,0,0);
00087         ai.data()[2] = i;
00088         if ( procNum(0,ai) != CkMyPe() ) NAMD_bug("PmePencilXYMap::populateInitial, map is inconsistent");
00089         mgr->insertInitial(ai, msg);
00090         msg = NULL;
00091       }
00092     }
00093     mgr->doneInserting();
00094     if (msg != NULL) CkFreeMsg(msg);
00095   }
00096 private:
00097   // List of Pes.
00098   const std::vector<int> pes;
00099 };
00100 
00101 class PmeStartMsg : public CMessage_PmeStartMsg {
00102 public:
00103   float *data;
00104   int dataSize;
00105   int device;
00106 };
00107 
00108 class PmeRunMsg : public CMessage_PmeRunMsg {
00109 public:
00110   bool doEnergy, doVirial;
00111   int numStrayAtoms;
00112   Lattice lattice;
00113 };
00114 
00115 class PmeSelfEnergyMsg : public CMessage_PmeSelfEnergyMsg {
00116 public:
00117   double energy;
00118 };
00119 
00120 class PmeDoneMsg : public CMessage_PmeDoneMsg {
00121 public:
00122   PmeDoneMsg(int i, int j) : i(i), j(j) {}
00123   int i, j;
00124 };
00125 
00126 class PmeBlockMsg : public CMessage_PmeBlockMsg {
00127 public:
00128   float2 *data;
00129   int dataSize;
00130   int x, y, z;
00131   bool doEnergy, doVirial;
00132   int numStrayAtoms;
00133   Lattice lattice;
00134 };
00135 
00136 class PmePencilXYZ : public CBase_PmePencilXYZ {
00137 public:
00138   PmePencilXYZ_SDAG_CODE
00139   PmePencilXYZ();
00140   PmePencilXYZ(CkMigrateMessage *m);
00141   virtual ~PmePencilXYZ();
00142   void skip();
00143 protected:
00144   PmeGrid pmeGrid;
00145   bool doEnergy, doVirial;
00146   FFTCompute* fftCompute;
00147   PmeKSpaceCompute* pmeKSpaceCompute;
00148   Lattice lattice;
00149   int numStrayAtoms;
00150   virtual void backwardDone();
00151   void submitReductions();
00152 private:
00153   void forwardFFT();
00154   void backwardFFT();
00155   void forwardDone();
00156   void initFFT(PmeStartMsg *msg);
00157 
00158   int numSelfEnergyRecv;
00159   bool firstIter;
00160   double selfEnergy;
00161   SubmitReduction* reduction;
00162 
00163 };
00164 
00165 class PmePencilXY : public CBase_PmePencilXY {
00166 public:
00167   PmePencilXY_SDAG_CODE
00168   PmePencilXY();
00169   PmePencilXY(CkMigrateMessage *m);
00170   virtual ~PmePencilXY();
00171 protected:
00172   PmeGrid pmeGrid;
00173   bool doEnergy, doVirial;
00174   FFTCompute* fftCompute;
00175   PmeTranspose* pmeTranspose;
00176   std::vector<int> blockSizes;
00177   Lattice lattice;
00178   int numStrayAtoms;
00179   void initBlockSizes();
00180   int imsg;
00181 private:
00182   void forwardFFT();
00183   void backwardFFT();
00184   void initFFT(PmeStartMsg *msg);
00185   virtual void forwardDone();
00186   virtual void backwardDone();
00187   virtual void recvDataFromZ(PmeBlockMsg *msg);
00188   virtual void start();
00189 
00190 };
00191 
00192 class PmePencilX : public CBase_PmePencilX {
00193 public:
00194   PmePencilX_SDAG_CODE
00195   PmePencilX();
00196   PmePencilX(CkMigrateMessage *m);
00197   virtual ~PmePencilX();
00198 protected:
00199   PmeGrid pmeGrid;
00200   bool doEnergy, doVirial;
00201   FFTCompute* fftCompute;
00202   PmeTranspose* pmeTranspose;
00203   std::vector<int> blockSizes;
00204   Lattice lattice;
00205   int numStrayAtoms;
00206   void initBlockSizes();
00207   int imsg;
00208 private:
00209   void forwardFFT();
00210   void backwardFFT();
00211   void initFFT(PmeStartMsg *msg);
00212   virtual void forwardDone();
00213   virtual void backwardDone();
00214   virtual void recvDataFromY(PmeBlockMsg *msg);
00215   virtual void start();
00216 
00217 };
00218 
00219 class PmePencilY : public CBase_PmePencilY {
00220 public:
00221   PmePencilY_SDAG_CODE
00222   PmePencilY();
00223   PmePencilY(CkMigrateMessage *m);
00224   virtual ~PmePencilY();
00225 protected:
00226   PmeGrid pmeGrid;
00227   bool doEnergy, doVirial;
00228   FFTCompute* fftCompute;
00229   PmeTranspose* pmeTranspose;
00230   std::vector<int> blockSizes;
00231   Lattice lattice;
00232   int numStrayAtoms;
00233   void initBlockSizes();
00234   int imsg;
00235 private:
00236   void forwardFFT();
00237   void backwardFFT();
00238   void initFFT(PmeStartMsg *msg);
00239   virtual void forwardDone();
00240   virtual void backwardDone();
00241   virtual void recvDataFromX(PmeBlockMsg *msg);
00242   virtual void recvDataFromZ(PmeBlockMsg *msg);
00243   virtual void start();
00244 
00245 };
00246 
00247 class PmePencilZ : public CBase_PmePencilZ {
00248 public:
00249   PmePencilZ_SDAG_CODE
00250   PmePencilZ();
00251   PmePencilZ(CkMigrateMessage *m);
00252   virtual ~PmePencilZ();
00253   void skip();
00254 protected:
00255   PmeGrid pmeGrid;
00256   bool doEnergy, doVirial;
00257   FFTCompute* fftCompute;
00258   PmeTranspose* pmeTranspose;
00259   PmeKSpaceCompute* pmeKSpaceCompute;
00260   std::vector<int> blockSizes;
00261   Lattice lattice;
00262   int numStrayAtoms;
00263   void initBlockSizes();
00264   void submitReductions();
00265   int imsg;
00266 private:
00267   void forwardFFT();
00268   void backwardFFT();
00269   void forwardDone();
00270   void initFFT(PmeStartMsg *msg);
00271   virtual void backwardDone();
00272   virtual void recvDataFromY(PmeBlockMsg *msg);
00273   virtual void start();
00274 
00275   int numSelfEnergyRecv;
00276   bool firstIter;
00277   double selfEnergy;
00278   SubmitReduction* reduction;
00279 
00280 };
00281 
00282 // #define CK_TEMPLATES_ONLY
00283 // #include "PmeSolver.def.h"
00284 // #undef CK_TEMPLATES_ONLY
00285 
00286 #endif // PMESOLVER_H

Generated on Mon Nov 20 01:17:14 2017 for NAMD by  doxygen 1.4.7