MsmC1HermiteGridCutoff Class Reference

Inheritance diagram for MsmC1HermiteGridCutoff:

MsmGridCutoffKernel< C1Vector, C1Matrix > List of all members.

Public Member Functions

 MsmC1HermiteGridCutoff ()
 MsmC1HermiteGridCutoff (CkMigrateMessage *m)
void init ()
void setup (MsmGridCutoffInitMsg *bmsg)
void setupSections (MsmC1HermiteGridCutoffSetupMsg *msg)
void compute (GridMsg *gmsg)
void compute_specialized (GridMsg *gmsg)

Public Attributes

CProxyElement_MsmC1HermiteBlock msmBlockElementProxy
CkSectionInfo cookie
msm::Grid< C1Vectorehfull

Detailed Description

Definition at line 2327 of file ComputeMsm.C.


Constructor & Destructor Documentation

MsmC1HermiteGridCutoff::MsmC1HermiteGridCutoff (  )  [inline]

Definition at line 2338 of file ComputeMsm.C.

02338 { }

MsmC1HermiteGridCutoff::MsmC1HermiteGridCutoff ( CkMigrateMessage *  m  )  [inline]

Definition at line 2340 of file ComputeMsm.C.

02342     { }


Member Function Documentation

void MsmC1HermiteGridCutoff::compute ( GridMsg gmsg  )  [inline]

Reimplemented from MsmGridCutoffKernel< C1Vector, C1Matrix >.

Definition at line 2407 of file ComputeMsm.C.

References ComputeMsmMgr::addPotential(), MsmTimer::COMM, MsmGridCutoffKernel< Vtype, Mtype >::compute(), msm::BlockIndex::level, msm::BlockIndex::n, GridMsg::put(), and SET_PRIORITY.

02407                                 {
02408 #ifdef DEBUG_MSM_GRID
02409       printf("MsmC1HermiteGridCutoff %d:  compute()\n", thisIndex);
02410 #endif
02411 #if 0
02412       // base class consumes this grid message
02413       MsmGridCutoffKernel<C1Vector,C1Matrix>::compute(gmsg);
02414 #else
02415       compute_specialized(gmsg);
02416 #endif
02417 
02418 #ifdef MSM_TIMING
02419       double startTime, stopTime;
02420       startTime = CkWallTimer();
02421 #endif
02422 #ifdef MSM_REDUCE_GRID
02423 
02424       // perform section reduction over potential grids
02425       CProxy_CkMulticastMgr mcastProxy =
02426         CkpvAccess(BOCclass_group).multicastMgr;
02427       CkMulticastMgr *mcastPtr =
02428         CProxy_CkMulticastMgr(mcastProxy).ckLocalBranch();
02429       CkCallback cb(CkIndex_MsmC1HermiteBlock::sumReducedPotential(NULL),
02430           msmBlockElementProxy);
02431       // sum into "full" sized buffer needed for contribute
02432       ehfull.reset(0);
02433       ehfull += eh;
02434       mcastPtr->contribute(
02435           ehfull.nn() * sizeof(C1Vector), ehfull.data().buffer(), 
02436           CkReduction::sum_float, cookie, cb);
02437 
02438 #else
02439       // place eh into message
02440       const msm::BlockIndex& bindex = ehblockSend.nblock_wrap;
02441       int msgsz = eh.data().len() * sizeof(C1Vector);
02442       GridMsg *gm = new(msgsz, sizeof(int)) GridMsg;
02443       SET_PRIORITY(gm, sequence, priority);
02444       gm->put(eh, bindex.level, sequence);
02445       // lookup in ComputeMsmMgr proxy array by level
02446       mgrLocal->msmC1HermiteBlock[bindex.level](
02447           bindex.n.i, bindex.n.j, bindex.n.k).addPotential(gm);
02448 
02449 #endif // MSM_REDUCE_GRID
02450 
02451 #ifdef MSM_TIMING
02452       stopTime = CkWallTimer();
02453       mgrLocal->msmTiming[MsmTimer::COMM] += stopTime - startTime;
02454       mgrLocal->doneTiming();
02455 #endif
02456     } // compute()

void MsmC1HermiteGridCutoff::compute_specialized ( GridMsg gmsg  ) 

Definition at line 2463 of file ComputeMsm.C.

References C1_VECTOR_SIZE, MsmTimer::COMM, msm::Grid< T >::data(), MsmGridCutoffKernel< C1Vector, C1Matrix >::eh, MsmGridCutoffKernel< C1Vector, C1Matrix >::ehblockSend, MsmGridCutoffKernel< C1Vector, C1Matrix >::ehfold, MsmGridCutoffKernel< C1Vector, C1Matrix >::eia, MsmGridCutoffKernel< C1Vector, C1Matrix >::eib, MsmGridCutoffKernel< C1Vector, C1Matrix >::eja, MsmGridCutoffKernel< C1Vector, C1Matrix >::ejb, MsmGridCutoffKernel< C1Vector, C1Matrix >::eka, MsmGridCutoffKernel< C1Vector, C1Matrix >::ekb, MsmGridCutoffKernel< C1Vector, C1Matrix >::eni, MsmGridCutoffKernel< C1Vector, C1Matrix >::enj, MsmGridCutoffKernel< C1Vector, C1Matrix >::enk, GridMsg::get(), MsmTimer::GRIDCUTOFF, msm::IndexRange::ia(), msm::IndexRange::ib(), msm::Grid< T >::init(), MsmGridCutoffKernel< C1Vector, C1Matrix >::isfold, j, msm::IndexRange::ja(), msm::IndexRange::jb(), msm::IndexRange::ka(), msm::IndexRange::kb(), msm::BlockIndex::level, MsmGridCutoffKernel< C1Vector, C1Matrix >::mgrLocal, msm::IndexRange::ni(), msm::IndexRange::nj(), msm::IndexRange::nk(), msm::BlockSend::nrange, msm::BlockSend::nrange_wrap, MsmGridCutoffKernel< C1Vector, C1Matrix >::pgc, MsmGridCutoffKernel< C1Vector, C1Matrix >::qh, MsmGridCutoffKernel< C1Vector, C1Matrix >::qhblockIndex, msm::Grid< T >::reset(), MsmGridCutoffKernel< C1Vector, C1Matrix >::sequence, msm::Grid< T >::set(), msm::Grid< T >::updateLower(), and C1Vector::velem.

02463                                                               {
02464 #ifdef MSM_TIMING
02465       double startTime, stopTime;
02466       startTime = CkWallTimer();
02467 #endif
02468       //
02469       // receive block of charges
02470       //
02471       int pid;
02472       // qh is resized only the first time, memory allocation persists
02473       gmsg->get(qh, pid, sequence);
02474       delete gmsg;
02475 #ifdef MSM_TIMING
02476       stopTime = CkWallTimer();
02477       mgrLocal->msmTiming[MsmTimer::COMM] += stopTime - startTime;
02478 #endif
02479 
02480       //
02481       // grid cutoff calculation
02482       // this charge block -> this potential block
02483       //
02484 
02485 #ifdef MSM_TIMING
02486       startTime = stopTime;
02487 #endif
02488       // resets indexing on block
02489       eh.init(ehblockSend.nrange);  // (always have to re-init nrange for eh)
02490       eh.reset(0);
02491       // index range of weights
02492       int gia = pgc->ia();
02493       int gib = pgc->ib();
02494       int gja = pgc->ja();
02495       int gjb = pgc->jb();
02496       int gka = pgc->ka();
02497       int gkb = pgc->kb();
02498       int gni = pgc->ni();
02499       int gnj = pgc->nj();
02500       // index range of charge grid
02501       int qia = qh.ia();
02502       int qib = qh.ib();
02503       int qja = qh.ja();
02504       int qjb = qh.jb();
02505       int qka = qh.ka();
02506       int qkb = qh.kb();
02507       int qni = qh.ni();
02508       int qnj = qh.nj();
02509       // index range of potentials
02510       int ia = eh.ia();
02511       int ib = eh.ib();
02512       int ja = eh.ja();
02513       int jb = eh.jb();
02514       int ka = eh.ka();
02515       int kb = eh.kb();
02516 
02517       int index = 0;
02518 
02519       // access buffers directly
02520       const C1Matrix *gcbuffer = pgc->data().buffer();
02521       const C1Vector *qhbuffer = qh.data().buffer();
02522       C1Vector *ehbuffer = eh.data().buffer();
02523 #ifdef DEBUG_MEMORY_ALIGNMENT
02524       printf("gcbuffer mem:  addr=%p  div32=%lu  mod32=%lu\n",
02525           gcbuffer,
02526           (unsigned long)(gcbuffer)/32,
02527           (unsigned long)(gcbuffer)%32);
02528       printf("qhbuffer mem:  addr=%p  div32=%lu  mod32=%lu\n",
02529           qhbuffer,
02530           (unsigned long)(qhbuffer)/32,
02531           (unsigned long)(qhbuffer)%32);
02532       printf("ehbuffer mem:  addr=%p  div32=%lu  mod32=%lu\n",
02533           ehbuffer,
02534           (unsigned long)(ehbuffer)/32,
02535           (unsigned long)(ehbuffer)%32);
02536 #endif
02537 
02538 #ifndef MSM_COMM_ONLY
02539       // loop over potentials
02540       for (int k = ka;  k <= kb;  k++) {
02541         // clip charges to weights along k
02542         int mka = ( qka >= gka + k ? qka : gka + k );
02543         int mkb = ( qkb <= gkb + k ? qkb : gkb + k );
02544 
02545         for (int j = ja;  j <= jb;  j++) {
02546           // clip charges to weights along j
02547           int mja = ( qja >= gja + j ? qja : gja + j );
02548           int mjb = ( qjb <= gjb + j ? qjb : gjb + j );
02549 
02550           for (int i = ia;  i <= ib;  i++) {
02551             // clip charges to weights along i
02552             int mia = ( qia >= gia + i ? qia : gia + i );
02553             int mib = ( qib <= gib + i ? qib : gib + i );
02554 
02555             // accumulate sum to this eh point
02556             C1Vector ehsum = 0;
02557 
02558             // loop over charge grid
02559             int nn = mib - mia + 1;
02560 
02561             {
02562               int qnji = qnj * qni;
02563               int qkoff = -qka*qnji - qja*qni - qia + mia;
02564               int gnji = gnj * gni;
02565               int gkoff = (-k-gka)*gnji + (-j-gja)*gni - i - gia + mia;
02566 
02567               for (int qk = mka;  qk <= mkb;  qk++) {
02568                 int qjkoff = qkoff + qk*qnji;
02569                 int gjkoff = gkoff + qk*gnji;
02570 
02571                 for (int qj = mja;  qj <= mjb;  qj++) {
02572                   const C1Vector *qbuf = qhbuffer + (qjkoff + qj*qni);
02573                   const C1Matrix *gbuf = gcbuffer + (gjkoff + qj*gni);
02574 #ifdef MSM_PROFILING
02575                   mgrLocal->xLoopCnt[nn]++;
02576 #endif
02577 // help the vectorizer make reasonable decisions
02578 #if defined(__INTEL_COMPILER)
02579 #pragma vector always 
02580 #endif
02581                   for (int ii = 0;  ii < nn;  ii++) {
02582 
02583 #if 0
02584                     ehsum += gbuf[ii] * qbuf[ii];
02585 #else
02586                     // skip matvec when matrix is 0
02587                     // first matrix element tells us if this is the case
02588                     if ( *((int *)(gbuf)) != 0) {
02589 
02590                       // expand matrix-vector multiply
02591 #if defined(__INTEL_COMPILER)
02592 #pragma vector always
02593 #endif
02594                       for (int km=0, jm=0;  jm < C1_VECTOR_SIZE;  jm++) {
02595                         for (int im=0;  im < C1_VECTOR_SIZE;  im++, km++) {
02596                           ehsum.velem[jm] += gbuf->melem[km] * qbuf->velem[im];
02597                         }
02598                       }
02599                     } // if
02600                     gbuf++;
02601                     qbuf++;
02602 #endif
02603                   }
02604                 }
02605               } // end loop over charge grid
02606 
02607             }
02608 
02609             ehbuffer[index] = ehsum;
02610             index++;
02611           }
02612         }
02613       } // end loop over potentials
02614 #endif // !MSM_COMM_ONLY
02615 
02616 #ifdef MSM_PROFILING
02617       mgrLocal->doneProfiling();
02618 #endif
02619 
02620       //
02621       // send block of potentials
02622       //
02623 
02624 #ifdef MSM_FOLD_FACTOR
02625       // if "fold factor" is active for this level,
02626       // need to sum unfolded potential grid back into periodic grid
02627       if (isfold) {
02628         // copy unfolded grid
02629         ehfold = eh;
02630         // reset eh indexing to correctly folded size
02631         eh.set(eia, eni, eja, enj, eka, enk);
02632         eh.reset(0);
02633 #ifdef DEBUG_MSM_GRID
02634         printf("level=%d   ehfold:  [%d..%d] x [%d..%d] x [%d..%d]  "
02635             "(%d x %d x %d)\n"
02636                 "              eh:  [%d..%d] x [%d..%d] x [%d..%d]  "
02637             "(%d x %d x %d)\n"
02638                "         eh lower:  %d %d %d\n",
02639             qhblockIndex.level,
02640             ehfold.ia(), ehfold.ib(), 
02641             ehfold.ja(), ehfold.jb(),
02642             ehfold.ka(), ehfold.kb(),
02643             ehfold.ni(), ehfold.nj(), ehfold.nk(),
02644             eh.ia(), eh.ib(), 
02645             eh.ja(), eh.jb(),
02646             eh.ka(), eh.kb(),
02647             eh.ni(), eh.nj(), eh.nk(),
02648             ehblockSend.nrange_wrap.lower().i,
02649             ehblockSend.nrange_wrap.lower().j,
02650             ehblockSend.nrange_wrap.lower().k
02651             );
02652 #endif
02653         const C1Vector *ehfoldbuf = ehfold.data().buffer();
02654         C1Vector *ehbuf = eh.data().buffer();
02655         // now we "fold" eh by calculating the
02656         // wrap around sum of ehfold into correctly sized eh
02657         int index = 0;
02658         for (int k = ka;  k <= kb;  k++) {
02659           int kk = k;
02660           if      (kk < eka)  do { kk += enk; } while (kk < eka);
02661           else if (kk > ekb)  do { kk -= enk; } while (kk > ekb);
02662           int koff = (kk - eka) * enj;
02663           for (int j = ja;  j <= jb;  j++) {
02664             int jj = j;
02665             if      (jj < eja)  do { jj += enj; } while (jj < eja);
02666             else if (jj > ejb)  do { jj -= enj; } while (jj > ejb);
02667             int jkoff = (koff + (jj - eja)) * eni;
02668             for (int i = ia;  i <= ib;  i++, index++) {
02669               int ii = i;
02670               if      (ii < eia)  do { ii += eni; } while (ii < eia);
02671               else if (ii > eib)  do { ii -= eni; } while (ii > eib);
02672               int ijkoff = jkoff + (ii - eia);
02673               ehbuf[ijkoff] += ehfoldbuf[index];
02674             }
02675           }
02676         }
02677       }
02678       else {
02679         // shift grid index range to its true (wrapped) values
02680         eh.updateLower( ehblockSend.nrange_wrap.lower() );
02681       }
02682 #else    // !MSM_FOLD_FACTOR
02683       // shift grid index range to its true (wrapped) values
02684       eh.updateLower( ehblockSend.nrange_wrap.lower() );
02685 #endif   // MSM_FOLD_FACTOR
02686 
02687 #ifdef MSM_TIMING
02688       stopTime = CkWallTimer();
02689       mgrLocal->msmTiming[MsmTimer::GRIDCUTOFF] += stopTime - startTime;
02690 #endif
02691 } // MsmC1HermiteGridCutoff::compute_specialized()

void MsmC1HermiteGridCutoff::init (  )  [inline]

Reimplemented from MsmGridCutoffKernel< C1Vector, C1Matrix >.

Definition at line 2367 of file ComputeMsm.C.

References MsmGridCutoffKernel< Vtype, Mtype >::init().

void MsmC1HermiteGridCutoff::setup ( MsmGridCutoffInitMsg bmsg  )  [inline]

Reimplemented from MsmGridCutoffKernel< C1Vector, C1Matrix >.

Definition at line 2371 of file ComputeMsm.C.

References msm::Map::blockLevel, msm::Map::gc_c1hermite, j, ComputeMsmMgr::map, MsmGridCutoffKernel< Vtype, Mtype >::setup(), and MsmGridCutoffKernel< Vtype, Mtype >::setupWeights().

02371                                            {
02372       // base class consumes this init proxy  message
02373       MsmGridCutoffKernel<C1Vector,C1Matrix>::setup(bmsg);
02374       // access type dependent constants from map
02375       MsmGridCutoffKernel<C1Vector,C1Matrix>::setupWeights(
02376           &(map->gc_c1hermite[ehblockSend.nblock_wrap.level]),
02377           NULL
02378           );
02379 #ifdef DEBUG_MSM_GRID
02380       printf("MsmC1HermiteGridCutoff[%d]:  setup()"
02381           " send to level=%d block=(%d,%d,%d)\n",
02382           thisIndex, ehblockSend.nblock_wrap.level,
02383           ehblockSend.nblock_wrap.n.i,
02384           ehblockSend.nblock_wrap.n.j,
02385           ehblockSend.nblock_wrap.n.k);
02386 #endif
02387 #ifdef MSM_REDUCE_GRID
02388       // allocate full buffer space needed for section reduction
02389       int level = ehblockSend.nblock_wrap.level;
02390       int i = ehblockSend.nblock_wrap.n.i;
02391       int j = ehblockSend.nblock_wrap.n.j;
02392       int k = ehblockSend.nblock_wrap.n.k;
02393       ehfull.init( map->blockLevel[level](i,j,k).nrange );
02394 #endif // MSM_REDUCE_GRID
02395     }

void MsmC1HermiteGridCutoff::setupSections ( MsmC1HermiteGridCutoffSetupMsg msg  )  [inline]

Definition at line 2397 of file ComputeMsm.C.

References MsmC1HermiteGridCutoffSetupMsg::get().

02397                                                             {
02398 #ifdef DEBUG_MSM_GRID
02399       CkPrintf("MSM C1 HERMITE GRID CUTOFF %d setup section on PE %d\n",
02400           thisIndex, CkMyPe());
02401 #endif
02402       CkGetSectionInfo(cookie, msg);  // init the cookie
02403       msg->get(&msmBlockElementProxy);  // get proxy to MsmC1HermiteBlock
02404       delete msg;
02405     }


Member Data Documentation

CkSectionInfo MsmC1HermiteGridCutoff::cookie

Definition at line 2333 of file ComputeMsm.C.

msm::Grid<C1Vector> MsmC1HermiteGridCutoff::ehfull

Definition at line 2335 of file ComputeMsm.C.

CProxyElement_MsmC1HermiteBlock MsmC1HermiteGridCutoff::msmBlockElementProxy

Definition at line 2332 of file ComputeMsm.C.


The documentation for this class was generated from the following file:
Generated on Mon Sep 25 01:17:18 2017 for NAMD by  doxygen 1.4.7