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 PmeDoneMsg : public CMessage_PmeDoneMsg {
00116 public:
00117   PmeDoneMsg(int i, int j) : i(i), j(j) {}
00118   int i, j;
00119 };
00120 
00121 class PmeBlockMsg : public CMessage_PmeBlockMsg {
00122 public:
00123   float2 *data;
00124   int dataSize;
00125   int x, y, z;
00126   bool doEnergy, doVirial;
00127   int numStrayAtoms;
00128   Lattice lattice;
00129 };
00130 
00131 class PmePencilXYZ : public CBase_PmePencilXYZ {
00132 public:
00133   PmePencilXYZ_SDAG_CODE
00134   PmePencilXYZ();
00135   PmePencilXYZ(CkMigrateMessage *m);
00136   virtual ~PmePencilXYZ();
00137   void skip();
00138 protected:
00139   PmeGrid pmeGrid;
00140   bool doEnergy, doVirial;
00141   FFTCompute* fftCompute;
00142   PmeKSpaceCompute* pmeKSpaceCompute;
00143   Lattice lattice;
00144   int numStrayAtoms;
00145   virtual void backwardDone();
00146   void submitReductions();
00147 private:
00148   void forwardFFT();
00149   void backwardFFT();
00150   void forwardDone();
00151   void initFFT(PmeStartMsg *msg);
00152 
00153   SubmitReduction* reduction;
00154 
00155 };
00156 
00157 class PmePencilXY : public CBase_PmePencilXY {
00158 public:
00159   PmePencilXY_SDAG_CODE
00160   PmePencilXY();
00161   PmePencilXY(CkMigrateMessage *m);
00162   virtual ~PmePencilXY();
00163 protected:
00164   PmeGrid pmeGrid;
00165   bool doEnergy, doVirial;
00166   FFTCompute* fftCompute;
00167   PmeTranspose* pmeTranspose;
00168   std::vector<int> blockSizes;
00169   Lattice lattice;
00170   int numStrayAtoms;
00171   void initBlockSizes();
00172   int imsg;
00173 private:
00174   void forwardFFT();
00175   void backwardFFT();
00176   void initFFT(PmeStartMsg *msg);
00177   virtual void forwardDone();
00178   virtual void backwardDone();
00179   virtual void recvDataFromZ(PmeBlockMsg *msg);
00180   virtual void start();
00181 
00182 };
00183 
00184 class PmePencilX : public CBase_PmePencilX {
00185 public:
00186   PmePencilX_SDAG_CODE
00187   PmePencilX();
00188   PmePencilX(CkMigrateMessage *m);
00189   virtual ~PmePencilX();
00190 protected:
00191   PmeGrid pmeGrid;
00192   bool doEnergy, doVirial;
00193   FFTCompute* fftCompute;
00194   PmeTranspose* pmeTranspose;
00195   std::vector<int> blockSizes;
00196   Lattice lattice;
00197   int numStrayAtoms;
00198   void initBlockSizes();
00199   int imsg;
00200 private:
00201   void forwardFFT();
00202   void backwardFFT();
00203   void initFFT(PmeStartMsg *msg);
00204   virtual void forwardDone();
00205   virtual void backwardDone();
00206   virtual void recvDataFromY(PmeBlockMsg *msg);
00207   virtual void start();
00208 
00209 };
00210 
00211 class PmePencilY : public CBase_PmePencilY {
00212 public:
00213   PmePencilY_SDAG_CODE
00214   PmePencilY();
00215   PmePencilY(CkMigrateMessage *m);
00216   virtual ~PmePencilY();
00217 protected:
00218   PmeGrid pmeGrid;
00219   bool doEnergy, doVirial;
00220   FFTCompute* fftCompute;
00221   PmeTranspose* pmeTranspose;
00222   std::vector<int> blockSizes;
00223   Lattice lattice;
00224   int numStrayAtoms;
00225   void initBlockSizes();
00226   int imsg;
00227 private:
00228   void forwardFFT();
00229   void backwardFFT();
00230   void initFFT(PmeStartMsg *msg);
00231   virtual void forwardDone();
00232   virtual void backwardDone();
00233   virtual void recvDataFromX(PmeBlockMsg *msg);
00234   virtual void recvDataFromZ(PmeBlockMsg *msg);
00235   virtual void start();
00236 
00237 };
00238 
00239 class PmePencilZ : public CBase_PmePencilZ {
00240 public:
00241   PmePencilZ_SDAG_CODE
00242   PmePencilZ();
00243   PmePencilZ(CkMigrateMessage *m);
00244   virtual ~PmePencilZ();
00245   void skip();
00246 protected:
00247   PmeGrid pmeGrid;
00248   bool doEnergy, doVirial;
00249   FFTCompute* fftCompute;
00250   PmeTranspose* pmeTranspose;
00251   PmeKSpaceCompute* pmeKSpaceCompute;
00252   std::vector<int> blockSizes;
00253   Lattice lattice;
00254   int numStrayAtoms;
00255   void initBlockSizes();
00256   void submitReductions();
00257   int imsg;
00258 private:
00259   void forwardFFT();
00260   void backwardFFT();
00261   void forwardDone();
00262   void initFFT(PmeStartMsg *msg);
00263   virtual void backwardDone();
00264   virtual void recvDataFromY(PmeBlockMsg *msg);
00265   virtual void start();
00266 
00267   SubmitReduction* reduction;
00268 
00269 };
00270 
00271 // #define CK_TEMPLATES_ONLY
00272 // #include "PmeSolver.def.h"
00273 // #undef CK_TEMPLATES_ONLY
00274 
00275 #endif // PMESOLVER_H

Generated on Sat Sep 22 01:17:15 2018 for NAMD by  doxygen 1.4.7