NAMD
Public Member Functions | Public Attributes | List of all members
MsmGridCutoffKernel< Vtype, Mtype > Class Template Reference

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.

1806 { init(); }

Member Function Documentation

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

Definition at line 1904 of file ComputeMsm.C.

1904  {
1905 #ifdef MSM_TIMING
1906  double startTime, stopTime;
1907  startTime = CkWallTimer();
1908 #endif
1909  //
1910  // receive block of charges
1911  //
1912  int pid;
1913  // qh is resized only the first time, memory allocation persists
1914  gmsg->get(qh, pid, sequence);
1915  delete gmsg;
1916 #ifdef MSM_TIMING
1917  stopTime = CkWallTimer();
1918  mgrLocal->msmTiming[MsmTimer::COMM] += stopTime - startTime;
1919 #endif
1920 
1921  //
1922  // grid cutoff calculation
1923  // this charge block -> this potential block
1924  //
1925 
1926 #ifdef MSM_TIMING
1927  startTime = stopTime;
1928 #endif
1929  // resets indexing on block
1930  eh.init(ehblockSend.nrange); // (always have to re-init nrange for eh)
1931  eh.reset(0);
1932  // index range of weights
1933  int gia = pgc->ia();
1934  int gib = pgc->ib();
1935  int gja = pgc->ja();
1936  int gjb = pgc->jb();
1937  int gka = pgc->ka();
1938  int gkb = pgc->kb();
1939  int gni = pgc->ni();
1940  int gnj = pgc->nj();
1941  // index range of charge grid
1942  int qia = qh.ia();
1943  int qib = qh.ib();
1944  int qja = qh.ja();
1945  int qjb = qh.jb();
1946  int qka = qh.ka();
1947  int qkb = qh.kb();
1948  int qni = qh.ni();
1949  int qnj = qh.nj();
1950  // index range of potentials
1951  int ia = eh.ia();
1952  int ib = eh.ib();
1953  int ja = eh.ja();
1954  int jb = eh.jb();
1955  int ka = eh.ka();
1956  int kb = eh.kb();
1957 
1958  int index = 0;
1959 
1960  // access buffers directly
1961  const Mtype *gcbuffer = pgc->data().buffer();
1962  //const Mtype *gvcbuffer = pgvc->data().buffer();
1963  const Vtype *qhbuffer = qh.data().buffer();
1964  Vtype *ehbuffer = eh.data().buffer();
1965  //Vtype *gvsumbuffer = mgrLocal->gvsum.data().buffer();
1966 
1967 #ifndef MSM_COMM_ONLY
1968  // loop over potentials
1969  for (int k = ka; k <= kb; k++) {
1970  // clip charges to weights along k
1971  int mka = ( qka >= gka + k ? qka : gka + k );
1972  int mkb = ( qkb <= gkb + k ? qkb : gkb + k );
1973 
1974  for (int j = ja; j <= jb; j++) {
1975  // clip charges to weights along j
1976  int mja = ( qja >= gja + j ? qja : gja + j );
1977  int mjb = ( qjb <= gjb + j ? qjb : gjb + j );
1978 
1979  for (int i = ia; i <= ib; i++) {
1980  // clip charges to weights along i
1981  int mia = ( qia >= gia + i ? qia : gia + i );
1982  int mib = ( qib <= gib + i ? qib : gib + i );
1983 
1984  // accumulate sum to this eh point
1985  Vtype ehsum = 0;
1986 
1987 #if 0
1988  // loop over charge grid
1989  for (int qk = mka; qk <= mkb; qk++) {
1990  int qkoff = (qk - qka) * qnj;
1991  int gkoff = ((qk-k) - gka) * gnj;
1992 
1993  for (int qj = mja; qj <= mjb; qj++) {
1994  int qjkoff = (qkoff + qj - qja) * qni;
1995  int gjkoff = (gkoff + (qj-j) - gja) * gni;
1996 
1997 // help the vectorizer make reasonable decisions
1998 #if defined(__INTEL_COMPILER)
1999 #pragma vector always
2000 #endif
2001  for (int qi = mia; qi <= mib; qi++) {
2002  int qijkoff = qjkoff + qi - qia;
2003  int gijkoff = gjkoff + (qi-i) - gia;
2004 
2005  ehsum += gcbuffer[gijkoff] * qhbuffer[qijkoff];
2006  }
2007  }
2008  } // end loop over charge grid
2009 #else
2010 
2011 #if 0
2012  // loop over charge grid
2013  int nn = mib - mia + 1;
2014  for (int qk = mka; qk <= mkb; qk++) {
2015  int qkoff = (qk - qka) * qnj;
2016  int gkoff = ((qk-k) - gka) * gnj;
2017 
2018  for (int qj = mja; qj <= mjb; qj++) {
2019  int qjkoff = (qkoff + qj - qja) * qni;
2020  int gjkoff = (gkoff + (qj-j) - gja) * gni;
2021 
2022  const Float *qbuf = qhbuffer + (qjkoff - qia + mia);
2023  const Float *gbuf = gcbuffer + (gjkoff - i - gia + mia);
2024 #ifdef MSM_PROFILING
2025  mgrLocal->xLoopCnt[nn]++;
2026 #endif
2027 // help the vectorizer make reasonable decisions
2028 #if defined(__INTEL_COMPILER)
2029 #pragma vector always
2030 #endif
2031  for (int ii = 0; ii < nn; ii++) {
2032  ehsum += gbuf[ii] * qbuf[ii];
2033  }
2034  }
2035  } // end loop over charge grid
2036 #else
2037  // loop over charge grid
2038  int nn = mib - mia + 1;
2039  if (nn == 8) { // hard coded inner loop = 8
2040  int qnji = qnj * qni;
2041  int qkoff = -qka*qnji - qja*qni - qia + mia;
2042  int gnji = gnj * gni;
2043  int gkoff = (-k-gka)*gnji + (-j-gja)*gni - i - gia + mia;
2044 
2045  for (int qk = mka; qk <= mkb; qk++) {
2046  int qjkoff = qkoff + qk*qnji;
2047  int gjkoff = gkoff + qk*gnji;
2048 
2049  for (int qj = mja; qj <= mjb; qj++) {
2050  const Vtype *qbuf = qhbuffer + (qjkoff + qj*qni);
2051  const Mtype *gbuf = gcbuffer + (gjkoff + qj*gni);
2052  //const Mtype *gvcbuf = gvcbuffer + (gjkoff + qj*gni);
2053  //Vtype *gvsumbuf = gvsumbuffer + (gjkoff + qj*gni);
2054 #ifdef MSM_PROFILING
2055  mgrLocal->xLoopCnt[nn]++;
2056 #endif
2057 // help the vectorizer make reasonable decisions
2058 #if defined(__INTEL_COMPILER)
2059 #pragma vector always
2060 #endif
2061  for (int ii = 0; ii < 8; ii++) {
2062  ehsum += gbuf[ii] * qbuf[ii];
2063  //gvsumbuf[ii] += qbuf[ii] * qbuf[ii] * gvcbuf[ii];
2064  }
2065  }
2066  } // end loop over charge grid
2067  }
2068  else { // variable length inner loop < 8
2069  int qnji = qnj * qni;
2070  int qkoff = -qka*qnji - qja*qni - qia + mia;
2071  int gnji = gnj * gni;
2072  int gkoff = (-k-gka)*gnji + (-j-gja)*gni - i - gia + mia;
2073 
2074  for (int qk = mka; qk <= mkb; qk++) {
2075  int qjkoff = qkoff + qk*qnji;
2076  int gjkoff = gkoff + qk*gnji;
2077 
2078  for (int qj = mja; qj <= mjb; qj++) {
2079  const Vtype *qbuf = qhbuffer + (qjkoff + qj*qni);
2080  const Mtype *gbuf = gcbuffer + (gjkoff + qj*gni);
2081  //const Mtype *gvcbuf = gvcbuffer + (gjkoff + qj*gni);
2082  //Vtype *gvsumbuf = gvsumbuffer + (gjkoff + qj*gni);
2083 #ifdef MSM_PROFILING
2084  mgrLocal->xLoopCnt[nn]++;
2085 #endif
2086 // help the vectorizer make reasonable decisions
2087 #if defined(__INTEL_COMPILER)
2088 #pragma vector always
2089 #endif
2090  for (int ii = 0; ii < nn; ii++) {
2091  ehsum += gbuf[ii] * qbuf[ii];
2092  //gvsumbuf[ii] += qbuf[ii] * qbuf[ii] * gvcbuf[ii];
2093  }
2094  }
2095  } // end loop over charge grid
2096  }
2097 #endif // 0
2098 
2099 #endif // 0
2100 
2101  ehbuffer[index] = ehsum;
2102  index++;
2103  }
2104  }
2105  } // end loop over potentials
2106 #endif // !MSM_COMM_ONLY
2107 
2108 #ifdef MSM_PROFILING
2109  mgrLocal->doneProfiling();
2110 #endif
2111 
2112  //
2113  // send block of potentials
2114  //
2115 
2116 #ifdef MSM_FOLD_FACTOR
2117  // if "fold factor" is active for this level,
2118  // need to sum unfolded potential grid back into periodic grid
2119  if (isfold) {
2120  // copy unfolded grid
2121  ehfold = eh;
2122  // reset eh indexing to correctly folded size
2123  eh.set(eia, eni, eja, enj, eka, enk);
2124  eh.reset(0);
2125 #ifdef DEBUG_MSM_GRID
2126  printf("level=%d ehfold: [%d..%d] x [%d..%d] x [%d..%d] "
2127  "(%d x %d x %d)\n"
2128  " eh: [%d..%d] x [%d..%d] x [%d..%d] "
2129  "(%d x %d x %d)\n"
2130  " eh lower: %d %d %d\n",
2132  ehfold.ia(), ehfold.ib(),
2133  ehfold.ja(), ehfold.jb(),
2134  ehfold.ka(), ehfold.kb(),
2135  ehfold.ni(), ehfold.nj(), ehfold.nk(),
2136  eh.ia(), eh.ib(),
2137  eh.ja(), eh.jb(),
2138  eh.ka(), eh.kb(),
2139  eh.ni(), eh.nj(), eh.nk(),
2143  );
2144 #endif
2145  const Vtype *ehfoldbuf = ehfold.data().buffer();
2146  Vtype *ehbuf = eh.data().buffer();
2147  // now we "fold" eh by calculating the
2148  // wrap around sum of ehfold into correctly sized eh
2149  int index = 0;
2150  for (int k = ka; k <= kb; k++) {
2151  int kk = k;
2152  if (kk < eka) do { kk += enk; } while (kk < eka);
2153  else if (kk > ekb) do { kk -= enk; } while (kk > ekb);
2154  int koff = (kk - eka) * enj;
2155  for (int j = ja; j <= jb; j++) {
2156  int jj = j;
2157  if (jj < eja) do { jj += enj; } while (jj < eja);
2158  else if (jj > ejb) do { jj -= enj; } while (jj > ejb);
2159  int jkoff = (koff + (jj - eja)) * eni;
2160  for (int i = ia; i <= ib; i++, index++) {
2161  int ii = i;
2162  if (ii < eia) do { ii += eni; } while (ii < eia);
2163  else if (ii > eib) do { ii -= eni; } while (ii > eib);
2164  int ijkoff = jkoff + (ii - eia);
2165  ehbuf[ijkoff] += ehfoldbuf[index];
2166  }
2167  }
2168  }
2169  }
2170  else {
2171  // shift grid index range to its true (wrapped) values
2173  }
2174 #else // !MSM_FOLD_FACTOR
2175  // shift grid index range to its true (wrapped) values
2177 #endif // MSM_FOLD_FACTOR
2178 
2179 #ifdef MSM_TIMING
2180  stopTime = CkWallTimer();
2181  mgrLocal->msmTiming[MsmTimer::GRIDCUTOFF] += stopTime - startTime;
2182 #endif
2183  } // compute()
void reset(const T &t)
Definition: MsmMap.h:670
int k
Definition: MsmMap.h:411
const Array< T > & data() const
Definition: MsmMap.h:666
msm::Grid< Vtype > ehfold
Definition: ComputeMsm.C:1800
int ka() const
Definition: MsmMap.h:438
int i
Definition: MsmMap.h:411
msm::Grid< Vtype > eh
Definition: ComputeMsm.C:1799
msm::BlockSend ehblockSend
Definition: ComputeMsm.C:1795
int ia() const
Definition: MsmMap.h:434
msm::BlockIndex qhblockIndex
Definition: ComputeMsm.C:1794
void set(int pia, int pni, int pja, int pnj, int pka, int pnk)
Definition: MsmMap.h:608
int j
Definition: MsmMap.h:411
void init(const IndexRange &n)
Definition: MsmMap.h:603
int kb() const
Definition: MsmMap.h:439
const msm::Grid< Mtype > * pgc
Definition: ComputeMsm.C:1801
int jb() const
Definition: MsmMap.h:437
IndexRange nrange
Definition: MsmMap.h:868
int nj() const
Definition: MsmMap.h:441
msm::Grid< Vtype > qh
Definition: ComputeMsm.C:1798
float Float
Definition: MsmMap.h:74
void updateLower(const Ivec &n)
Definition: MsmMap.h:677
int nk() const
Definition: MsmMap.h:442
IndexRange nrange_wrap
Definition: MsmMap.h:870
ComputeMsmMgr * mgrLocal
Definition: ComputeMsm.C:1792
int ib() const
Definition: MsmMap.h:435
Ivec lower() const
Definition: MsmMap.h:444
int ja() const
Definition: MsmMap.h:436
void get(msm::Grid< T > &g, int &id, int &seq)
Definition: ComputeMsm.C:141
int ni() const
Definition: MsmMap.h:440
const T * buffer() const
Definition: MsmMap.h:259
template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::init ( )
inline

Definition at line 1808 of file ComputeMsm.C.

1808  {
1809  isfold = 0;
1810  mgrLocal = CProxy_ComputeMsmMgr::ckLocalBranch(
1811  CkpvAccess(BOCclass_group).computeMsmMgr);
1812  map = &(mgrLocal->mapData());
1814 #ifdef MSM_TIMING
1815  mgrLocal->addTiming();
1816 #endif
1817 #ifdef MSM_PROFILING
1818  mgrLocal->addProfiling();
1819 #endif
1820  }
msm::Map & mapData()
Definition: ComputeMsm.C:447
ComputeMsmMgr * mgrLocal
Definition: ComputeMsm.C:1792
void addVirialContrib()
Definition: ComputeMsm.C:533
template<class Vtype, class Mtype>
void MsmGridCutoffKernel< Vtype, Mtype >::setup ( MsmGridCutoffInitMsg bmsg)
inline

Definition at line 1838 of file ComputeMsm.C.

1838  {
1839  qhblockIndex = bmsg->qhBlockIndex;
1840  ehblockSend = bmsg->ehBlockSend;
1841  delete bmsg;
1842 
1843  // set message priority
1846  // allocate qh buffer
1848  // allocate eh buffer
1850  // preprocess "fold factor" if active for this level
1851  if (map->foldfactor[qhblockIndex.level].active) {
1852  // allocate ehfold buffer
1853  ehfold = eh;
1854  // set index range of potentials
1855  eia = eh.ia();
1856  eib = eh.ib();
1857  eja = eh.ja();
1858  ejb = eh.jb();
1859  eka = eh.ka();
1860  ekb = eh.kb();
1861  eni = eh.ni();
1862  enj = eh.nj();
1863  enk = eh.nk();
1864  if (map->blockLevel[qhblockIndex.level].nn() == 1) {
1865  if (map->ispx) { eia = qh.ia(); eib = qh.ib(); eni = qh.ni(); }
1866  if (map->ispy) { eja = qh.ja(); ejb = qh.jb(); enj = qh.nj(); }
1867  if (map->ispz) { eka = qh.ka(); ekb = qh.kb(); enk = qh.nk(); }
1868  }
1869  else {
1870  // find destination block index
1871  int level = qhblockIndex.level;
1873  ehblockSend.nrange_wrap.lower(), level);
1874  map->wrapBlockIndex(bn);
1875  if (map->ispx) {
1876  eia = bn.n.i * map->bsx[level];
1877  eib = eia + qh.ni() - 1;
1878  eni = qh.ni();
1879  }
1880  if (map->ispy) {
1881  eja = bn.n.j * map->bsy[level];
1882  ejb = eja + qh.nj() - 1;
1883  enj = qh.nj();
1884  }
1885  if (map->ispz) {
1886  eka = bn.n.k * map->bsz[level];
1887  ekb = eka + qh.nk() - 1;
1888  enk = qh.nk();
1889  }
1890  }
1891  isfold = 1;
1892  } // if fold factor
1893  } // setup()
Array< int > bsz
Definition: MsmMap.h:960
BlockIndex nblock_wrap
Definition: MsmMap.h:869
int k
Definition: MsmMap.h:411
msm::Grid< Vtype > ehfold
Definition: ComputeMsm.C:1800
Array< int > bsy
Definition: MsmMap.h:960
int ispx
Definition: MsmMap.h:958
int ka() const
Definition: MsmMap.h:438
int i
Definition: MsmMap.h:411
msm::Grid< Vtype > eh
Definition: ComputeMsm.C:1799
int ispy
Definition: MsmMap.h:958
msm::BlockSend ehblockSend
Definition: ComputeMsm.C:1795
int ia() const
Definition: MsmMap.h:434
msm::BlockIndex qhblockIndex
Definition: ComputeMsm.C:1794
BlockIndex blockOfGridIndex(const Ivec &n, int level) const
Definition: MsmMap.h:991
int ispz
Definition: MsmMap.h:958
Array< Grid< BlockDiagram > > blockLevel
Definition: MsmMap.h:956
int j
Definition: MsmMap.h:411
msm::BlockIndex qhBlockIndex
Definition: ComputeMsm.C:238
void init(const IndexRange &n)
Definition: MsmMap.h:603
int kb() const
Definition: MsmMap.h:439
int jb() const
Definition: MsmMap.h:437
IndexRange nrange
Definition: MsmMap.h:868
int nj() const
Definition: MsmMap.h:441
Array< int > bsx
Definition: MsmMap.h:960
msm::BlockSend ehBlockSend
Definition: ComputeMsm.C:239
msm::Grid< Vtype > qh
Definition: ComputeMsm.C:1798
void wrapBlockIndex(BlockIndex &bn) const
Definition: MsmMap.h:1214
int nk() const
Definition: MsmMap.h:442
IndexRange nrange_wrap
Definition: MsmMap.h:870
Array< FoldFactor > foldfactor
Definition: MsmMap.h:962
ComputeMsmMgr * mgrLocal
Definition: ComputeMsm.C:1792
int ib() const
Definition: MsmMap.h:435
Ivec lower() const
Definition: MsmMap.h:444
int ja() const
Definition: MsmMap.h:436
int ni() const
Definition: MsmMap.h:440
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.

1898  {
1899  pgc = ptrgc;
1900  pgvc = ptrgvc;
1901  } // setupWeights()
const msm::Grid< Mtype > * pgc
Definition: ComputeMsm.C:1801
const msm::Grid< Mtype > * pgvc
Definition: ComputeMsm.C:1802

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: