MsmGridCutoffKernel< Vtype, Mtype > Class Template Reference

Inheritance diagram for MsmGridCutoffKernel< Vtype, Mtype >:

MsmGridCutoff List of all members.

Public Member Functions

 MsmGridCutoffKernel ()
void init ()
void setup (MsmGridCutoffInitMsg *bmsg)
void setupWeights (const msm::Grid< Mtype > *ptrgc, const msm::Grid< Mtype > *ptrgvc)
void compute (GridMsg *gmsg)

Public Attributes

ComputeMsmMgrmgrLocal
msm::Mapmap
msm::BlockIndex qhblockIndex
msm::BlockSend ehblockSend
int eia
int eib
int eja
int ejb
int eka
int ekb
int eni
int enj
int enk
int isfold
msm::Grid< Vtype > qh
msm::Grid< Vtype > eh
msm::Grid< Vtype > ehfold
const msm::Grid< Mtype > * pgc
const msm::Grid< Mtype > * pgvc
int priority
int sequence

Detailed Description

template<class Vtype, class Mtype>
class MsmGridCutoffKernel< Vtype, Mtype >

Definition at line 1790 of file ComputeMsm.C.


Constructor & Destructor Documentation

template<class Vtype, class Mtype>
MsmGridCutoffKernel< Vtype, Mtype >::MsmGridCutoffKernel (  )  [inline]

Definition at line 1806 of file ComputeMsm.C.

01806 { init(); }


Member Function Documentation

template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::compute ( GridMsg gmsg  )  [inline]

Reimplemented in MsmGridCutoff, and MsmC1HermiteGridCutoff.

Definition at line 1904 of file ComputeMsm.C.

Referenced by MsmC1HermiteGridCutoff::compute(), and MsmGridCutoff::compute().

01904                                 {
01905 #ifdef MSM_TIMING
01906       double startTime, stopTime;
01907       startTime = CkWallTimer();
01908 #endif
01909       //
01910       // receive block of charges
01911       //
01912       int pid;
01913       // qh is resized only the first time, memory allocation persists
01914       gmsg->get(qh, pid, sequence);
01915       delete gmsg;
01916 #ifdef MSM_TIMING
01917       stopTime = CkWallTimer();
01918       mgrLocal->msmTiming[MsmTimer::COMM] += stopTime - startTime;
01919 #endif
01920 
01921       //
01922       // grid cutoff calculation
01923       // this charge block -> this potential block
01924       //
01925 
01926 #ifdef MSM_TIMING
01927       startTime = stopTime;
01928 #endif
01929       // resets indexing on block
01930       eh.init(ehblockSend.nrange);  // (always have to re-init nrange for eh)
01931       eh.reset(0);
01932       // index range of weights
01933       int gia = pgc->ia();
01934       int gib = pgc->ib();
01935       int gja = pgc->ja();
01936       int gjb = pgc->jb();
01937       int gka = pgc->ka();
01938       int gkb = pgc->kb();
01939       int gni = pgc->ni();
01940       int gnj = pgc->nj();
01941       // index range of charge grid
01942       int qia = qh.ia();
01943       int qib = qh.ib();
01944       int qja = qh.ja();
01945       int qjb = qh.jb();
01946       int qka = qh.ka();
01947       int qkb = qh.kb();
01948       int qni = qh.ni();
01949       int qnj = qh.nj();
01950       // index range of potentials
01951       int ia = eh.ia();
01952       int ib = eh.ib();
01953       int ja = eh.ja();
01954       int jb = eh.jb();
01955       int ka = eh.ka();
01956       int kb = eh.kb();
01957 
01958       int index = 0;
01959 
01960       // access buffers directly
01961       const Mtype *gcbuffer = pgc->data().buffer();
01962       //const Mtype *gvcbuffer = pgvc->data().buffer();
01963       const Vtype *qhbuffer = qh.data().buffer();
01964       Vtype *ehbuffer = eh.data().buffer();
01965       //Vtype *gvsumbuffer = mgrLocal->gvsum.data().buffer();
01966 
01967 #ifndef MSM_COMM_ONLY
01968       // loop over potentials
01969       for (int k = ka;  k <= kb;  k++) {
01970         // clip charges to weights along k
01971         int mka = ( qka >= gka + k ? qka : gka + k );
01972         int mkb = ( qkb <= gkb + k ? qkb : gkb + k );
01973 
01974         for (int j = ja;  j <= jb;  j++) {
01975           // clip charges to weights along j
01976           int mja = ( qja >= gja + j ? qja : gja + j );
01977           int mjb = ( qjb <= gjb + j ? qjb : gjb + j );
01978 
01979           for (int i = ia;  i <= ib;  i++) {
01980             // clip charges to weights along i
01981             int mia = ( qia >= gia + i ? qia : gia + i );
01982             int mib = ( qib <= gib + i ? qib : gib + i );
01983 
01984             // accumulate sum to this eh point
01985             Vtype ehsum = 0;
01986 
01987 #if 0
01988             // loop over charge grid
01989             for (int qk = mka;  qk <= mkb;  qk++) {
01990               int qkoff = (qk - qka) * qnj;
01991               int gkoff = ((qk-k) - gka) * gnj;
01992 
01993               for (int qj = mja;  qj <= mjb;  qj++) {
01994                 int qjkoff = (qkoff + qj - qja) * qni;
01995                 int gjkoff = (gkoff + (qj-j) - gja) * gni;
01996 
01997 // help the vectorizer make reasonable decisions
01998 #if defined(__INTEL_COMPILER)
01999 #pragma vector always 
02000 #endif
02001                 for (int qi = mia;  qi <= mib;  qi++) {
02002                   int qijkoff = qjkoff + qi - qia;
02003                   int gijkoff = gjkoff + (qi-i) - gia;
02004 
02005                   ehsum += gcbuffer[gijkoff] * qhbuffer[qijkoff];
02006                 }
02007               }
02008             } // end loop over charge grid
02009 #else
02010 
02011 #if 0
02012             // loop over charge grid
02013             int nn = mib - mia + 1;
02014             for (int qk = mka;  qk <= mkb;  qk++) {
02015               int qkoff = (qk - qka) * qnj;
02016               int gkoff = ((qk-k) - gka) * gnj;
02017 
02018               for (int qj = mja;  qj <= mjb;  qj++) {
02019                 int qjkoff = (qkoff + qj - qja) * qni;
02020                 int gjkoff = (gkoff + (qj-j) - gja) * gni;
02021 
02022                 const Float *qbuf = qhbuffer + (qjkoff - qia + mia);
02023                 const Float *gbuf = gcbuffer + (gjkoff - i - gia + mia);
02024 #ifdef MSM_PROFILING
02025                 mgrLocal->xLoopCnt[nn]++;
02026 #endif
02027 // help the vectorizer make reasonable decisions
02028 #if defined(__INTEL_COMPILER)
02029 #pragma vector always 
02030 #endif
02031                 for (int ii = 0;  ii < nn;  ii++) {
02032                   ehsum += gbuf[ii] * qbuf[ii];
02033                 }
02034               }
02035             } // end loop over charge grid
02036 #else
02037             // loop over charge grid
02038             int nn = mib - mia + 1;
02039             if (nn == 8) {  // hard coded inner loop = 8
02040               int qnji = qnj * qni;
02041               int qkoff = -qka*qnji - qja*qni - qia + mia;
02042               int gnji = gnj * gni;
02043               int gkoff = (-k-gka)*gnji + (-j-gja)*gni - i - gia + mia;
02044 
02045               for (int qk = mka;  qk <= mkb;  qk++) {
02046                 int qjkoff = qkoff + qk*qnji;
02047                 int gjkoff = gkoff + qk*gnji;
02048 
02049                 for (int qj = mja;  qj <= mjb;  qj++) {
02050                   const Vtype *qbuf = qhbuffer + (qjkoff + qj*qni);
02051                   const Mtype *gbuf = gcbuffer + (gjkoff + qj*gni);
02052                   //const Mtype *gvcbuf = gvcbuffer + (gjkoff + qj*gni);
02053                   //Vtype *gvsumbuf = gvsumbuffer + (gjkoff + qj*gni);
02054 #ifdef MSM_PROFILING
02055                   mgrLocal->xLoopCnt[nn]++;
02056 #endif
02057 // help the vectorizer make reasonable decisions
02058 #if defined(__INTEL_COMPILER)
02059 #pragma vector always 
02060 #endif
02061                   for (int ii = 0;  ii < 8;  ii++) {
02062                     ehsum += gbuf[ii] * qbuf[ii];
02063                     //gvsumbuf[ii] += qbuf[ii] * qbuf[ii] * gvcbuf[ii];
02064                   }
02065                 }
02066               } // end loop over charge grid
02067             }
02068             else {  // variable length inner loop < 8
02069               int qnji = qnj * qni;
02070               int qkoff = -qka*qnji - qja*qni - qia + mia;
02071               int gnji = gnj * gni;
02072               int gkoff = (-k-gka)*gnji + (-j-gja)*gni - i - gia + mia;
02073 
02074               for (int qk = mka;  qk <= mkb;  qk++) {
02075                 int qjkoff = qkoff + qk*qnji;
02076                 int gjkoff = gkoff + qk*gnji;
02077 
02078                 for (int qj = mja;  qj <= mjb;  qj++) {
02079                   const Vtype *qbuf = qhbuffer + (qjkoff + qj*qni);
02080                   const Mtype *gbuf = gcbuffer + (gjkoff + qj*gni);
02081                   //const Mtype *gvcbuf = gvcbuffer + (gjkoff + qj*gni);
02082                   //Vtype *gvsumbuf = gvsumbuffer + (gjkoff + qj*gni);
02083 #ifdef MSM_PROFILING
02084                   mgrLocal->xLoopCnt[nn]++;
02085 #endif
02086 // help the vectorizer make reasonable decisions
02087 #if defined(__INTEL_COMPILER)
02088 #pragma vector always 
02089 #endif
02090                   for (int ii = 0;  ii < nn;  ii++) {
02091                     ehsum += gbuf[ii] * qbuf[ii];
02092                     //gvsumbuf[ii] += qbuf[ii] * qbuf[ii] * gvcbuf[ii];
02093                   }
02094                 }
02095               } // end loop over charge grid
02096             }
02097 #endif // 0
02098 
02099 #endif // 0
02100 
02101             ehbuffer[index] = ehsum;
02102             index++;
02103           }
02104         }
02105       } // end loop over potentials
02106 #endif // !MSM_COMM_ONLY
02107 
02108 #ifdef MSM_PROFILING
02109       mgrLocal->doneProfiling();
02110 #endif
02111 
02112       //
02113       // send block of potentials
02114       //
02115 
02116 #ifdef MSM_FOLD_FACTOR
02117       // if "fold factor" is active for this level,
02118       // need to sum unfolded potential grid back into periodic grid
02119       if (isfold) {
02120         // copy unfolded grid
02121         ehfold = eh;
02122         // reset eh indexing to correctly folded size
02123         eh.set(eia, eni, eja, enj, eka, enk);
02124         eh.reset(0);
02125 #ifdef DEBUG_MSM_GRID
02126         printf("level=%d   ehfold:  [%d..%d] x [%d..%d] x [%d..%d]  "
02127             "(%d x %d x %d)\n"
02128                 "              eh:  [%d..%d] x [%d..%d] x [%d..%d]  "
02129             "(%d x %d x %d)\n"
02130                "         eh lower:  %d %d %d\n",
02131             qhblockIndex.level,
02132             ehfold.ia(), ehfold.ib(), 
02133             ehfold.ja(), ehfold.jb(),
02134             ehfold.ka(), ehfold.kb(),
02135             ehfold.ni(), ehfold.nj(), ehfold.nk(),
02136             eh.ia(), eh.ib(), 
02137             eh.ja(), eh.jb(),
02138             eh.ka(), eh.kb(),
02139             eh.ni(), eh.nj(), eh.nk(),
02140             ehblockSend.nrange_wrap.lower().i,
02141             ehblockSend.nrange_wrap.lower().j,
02142             ehblockSend.nrange_wrap.lower().k
02143             );
02144 #endif
02145         const Vtype *ehfoldbuf = ehfold.data().buffer();
02146         Vtype *ehbuf = eh.data().buffer();
02147         // now we "fold" eh by calculating the
02148         // wrap around sum of ehfold into correctly sized eh
02149         int index = 0;
02150         for (int k = ka;  k <= kb;  k++) {
02151           int kk = k;
02152           if      (kk < eka)  do { kk += enk; } while (kk < eka);
02153           else if (kk > ekb)  do { kk -= enk; } while (kk > ekb);
02154           int koff = (kk - eka) * enj;
02155           for (int j = ja;  j <= jb;  j++) {
02156             int jj = j;
02157             if      (jj < eja)  do { jj += enj; } while (jj < eja);
02158             else if (jj > ejb)  do { jj -= enj; } while (jj > ejb);
02159             int jkoff = (koff + (jj - eja)) * eni;
02160             for (int i = ia;  i <= ib;  i++, index++) {
02161               int ii = i;
02162               if      (ii < eia)  do { ii += eni; } while (ii < eia);
02163               else if (ii > eib)  do { ii -= eni; } while (ii > eib);
02164               int ijkoff = jkoff + (ii - eia);
02165               ehbuf[ijkoff] += ehfoldbuf[index];
02166             }
02167           }
02168         }
02169       }
02170       else {
02171         // shift grid index range to its true (wrapped) values
02172         eh.updateLower( ehblockSend.nrange_wrap.lower() );
02173       }
02174 #else    // !MSM_FOLD_FACTOR
02175       // shift grid index range to its true (wrapped) values
02176       eh.updateLower( ehblockSend.nrange_wrap.lower() );
02177 #endif   // MSM_FOLD_FACTOR
02178 
02179 #ifdef MSM_TIMING
02180       stopTime = CkWallTimer();
02181       mgrLocal->msmTiming[MsmTimer::GRIDCUTOFF] += stopTime - startTime;
02182 #endif
02183     } // compute()

template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::init (  )  [inline]

Reimplemented in MsmGridCutoff, and MsmC1HermiteGridCutoff.

Definition at line 1808 of file ComputeMsm.C.

Referenced by MsmC1HermiteGridCutoff::init(), and MsmGridCutoff::init().

01808                 {
01809       isfold = 0;
01810       mgrLocal = CProxy_ComputeMsmMgr::ckLocalBranch(
01811           CkpvAccess(BOCclass_group).computeMsmMgr);
01812       map = &(mgrLocal->mapData());
01813       mgrLocal->addVirialContrib();
01814 #ifdef MSM_TIMING
01815       mgrLocal->addTiming();
01816 #endif
01817 #ifdef MSM_PROFILING
01818       mgrLocal->addProfiling();
01819 #endif
01820     }

template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::setup ( MsmGridCutoffInitMsg bmsg  )  [inline]

Reimplemented in MsmGridCutoff, and MsmC1HermiteGridCutoff.

Definition at line 1838 of file ComputeMsm.C.

Referenced by MsmC1HermiteGridCutoff::setup(), and MsmGridCutoff::setup().

01838                                            {
01839       qhblockIndex = bmsg->qhBlockIndex;
01840       ehblockSend = bmsg->ehBlockSend;
01841       delete bmsg;
01842 
01843       // set message priority
01844       priority = mgrLocal->nlevels
01845         + 2*(mgrLocal->nlevels - ehblockSend.nblock_wrap.level) - 1;
01846       // allocate qh buffer
01847       qh.init(map->blockLevel[qhblockIndex.level](qhblockIndex.n).nrange);
01848       // allocate eh buffer
01849       eh.init(ehblockSend.nrange);
01850       // preprocess "fold factor" if active for this level
01851       if (map->foldfactor[qhblockIndex.level].active) {
01852         // allocate ehfold buffer
01853         ehfold = eh;
01854         // set index range of potentials
01855         eia = eh.ia();
01856         eib = eh.ib();
01857         eja = eh.ja();
01858         ejb = eh.jb();
01859         eka = eh.ka();
01860         ekb = eh.kb();
01861         eni = eh.ni();
01862         enj = eh.nj();
01863         enk = eh.nk();
01864         if (map->blockLevel[qhblockIndex.level].nn() == 1) {
01865           if (map->ispx) { eia = qh.ia();  eib = qh.ib();  eni = qh.ni(); }
01866           if (map->ispy) { eja = qh.ja();  ejb = qh.jb();  enj = qh.nj(); }
01867           if (map->ispz) { eka = qh.ka();  ekb = qh.kb();  enk = qh.nk(); }
01868         }
01869         else {
01870           // find destination block index
01871           int level = qhblockIndex.level;
01872           msm::BlockIndex bn = map->blockOfGridIndex(
01873               ehblockSend.nrange_wrap.lower(), level);
01874           map->wrapBlockIndex(bn);
01875           if (map->ispx) {
01876             eia = bn.n.i * map->bsx[level];
01877             eib = eia + qh.ni() - 1;
01878             eni = qh.ni();
01879           }
01880           if (map->ispy) {
01881             eja = bn.n.j * map->bsy[level];
01882             ejb = eja + qh.nj() - 1;
01883             enj = qh.nj();
01884           }
01885           if (map->ispz) {
01886             eka = bn.n.k * map->bsz[level];
01887             ekb = eka + qh.nk() - 1;
01888             enk = qh.nk();
01889           }
01890         }
01891         isfold = 1;
01892       } // if fold factor
01893     } // setup()

template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::setupWeights ( const msm::Grid< Mtype > *  ptrgc,
const msm::Grid< Mtype > *  ptrgvc 
) [inline]

Definition at line 1895 of file ComputeMsm.C.

Referenced by MsmC1HermiteGridCutoff::setup(), and MsmGridCutoff::setup().

01898           {
01899       pgc = ptrgc;
01900       pgvc = ptrgvc;
01901     } // setupWeights()


Member Data Documentation

template<class Vtype, class Mtype>
msm::Grid<Vtype> MsmGridCutoffKernel< Vtype, Mtype >::eh

Definition at line 1799 of file ComputeMsm.C.

template<class Vtype, class Mtype>
msm::BlockSend MsmGridCutoffKernel< Vtype, Mtype >::ehblockSend

Definition at line 1795 of file ComputeMsm.C.

template<class Vtype, class Mtype>
msm::Grid<Vtype> MsmGridCutoffKernel< Vtype, Mtype >::ehfold

Definition at line 1800 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::eia

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::eib

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::eja

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::ejb

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::eka

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::ekb

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::eni

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::enj

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::enk

Definition at line 1796 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::isfold

Definition at line 1797 of file ComputeMsm.C.

template<class Vtype, class Mtype>
msm::Map* MsmGridCutoffKernel< Vtype, Mtype >::map

Definition at line 1793 of file ComputeMsm.C.

template<class Vtype, class Mtype>
ComputeMsmMgr* MsmGridCutoffKernel< Vtype, Mtype >::mgrLocal

Definition at line 1792 of file ComputeMsm.C.

template<class Vtype, class Mtype>
const msm::Grid<Mtype>* MsmGridCutoffKernel< Vtype, Mtype >::pgc

Definition at line 1801 of file ComputeMsm.C.

template<class Vtype, class Mtype>
const msm::Grid<Mtype>* MsmGridCutoffKernel< Vtype, Mtype >::pgvc

Definition at line 1802 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::priority

Definition at line 1803 of file ComputeMsm.C.

template<class Vtype, class Mtype>
msm::Grid<Vtype> MsmGridCutoffKernel< Vtype, Mtype >::qh

Definition at line 1798 of file ComputeMsm.C.

template<class Vtype, class Mtype>
msm::BlockIndex MsmGridCutoffKernel< Vtype, Mtype >::qhblockIndex

Definition at line 1794 of file ComputeMsm.C.

template<class Vtype, class Mtype>
int MsmGridCutoffKernel< Vtype, Mtype >::sequence

Definition at line 1804 of file ComputeMsm.C.


The documentation for this class was generated from the following file:
Generated on Wed Sep 20 01:17:19 2017 for NAMD by  doxygen 1.4.7