Skip to content

How to refactor PooledMemory usage

Ye Luo edited this page Apr 30, 2020 · 3 revisions

Current implementation

PooledMemory belongs to a walker.

In the old code TWF is used as slots. N_TWF /= N_w. This pattern is actually unnecessary. When system is big, N_w is typically the same as N_TWF. When system is small, memory is not an issue even TWF needs more memory than N_w. So we can afford N_TWF = N_w.

  1. registerBuffer reserves size of TWF needed memory in the PM of walkers.
  2. Before an calculation, copyFromBuffer takes data from PM
  3. A the end of advanceWalkers, updateBuffer sends data to PM.

The current WFC operates in two modes.

  1. copyFromBuffer/updateBuffer may copy memory. Very high cost
  2. copyFromBuffer/updateBuffer may attach, detach memory. Relatively unsafe.

The advantage of PM. It is a single contiguous resident memory and can issue single MPI isend/recv.

Proposed change

No more use PM but use WalkerExchangeMemView. It is restricted to branching step only. WalkerExchangeMemView holds a list of memory regions by address to be exchanged.

Each WFC implements

WFC::contributeView(WalkerExchangeMemView& view)
{
   view.add(psiM.first_address(), psiM.last_address()); // vector, matrix....
   view.add(&logpsi); // scalar
}

WalkerExchangeMemView
{
  add() // add a memory segment in to the view.
  operator =() // for copy walkers within an MPI rank.
  isend/ircev() // for beyond an MPI rank.
  packing/unpacking() // for small memory segment as an optimization.
}