chombo-discharge
Loading...
Searching...
No Matches
Namespaces | Functions
CD_ParticleLoops.H File Reference

Declaration of a namespace for SIMD-decorated loops over SoA particles. More...

#include <cstddef>
#include <CD_Decorations.H>
#include <CD_ParticleSoA.H>
#include <CD_NamespaceHeader.H>
#include <CD_NamespaceFooter.H>
Include dependency graph for CD_ParticleLoops.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  ParticleLoops
 Namespace for SIMD-decorated loops over SoA particles (particle analogue of BoxLoops).
 

Functions

template<typename P , typename Traits , typename Functor >
ALWAYS_INLINE void ParticleLoops::loop (const ParticleSoA< P, Traits > &a_soa, Functor &&a_kernel)
 Launch a kernel over every particle in a ParticleSoA, decorating the loop with CD_PRAGMA_SIMD.
 
template<typename P , typename Traits , typename T , typename Functor >
ALWAYS_INLINE T ParticleLoops::reduce (const ParticleSoA< P, Traits > &a_soa, T a_initial, Functor &&a_kernel)
 Fold a kernel over every particle in a ParticleSoA, accumulating a reduction value.
 

Detailed Description

Declaration of a namespace for SIMD-decorated loops over SoA particles.

Author
Robert Marskar

ParticleLoops is the particle analogue of BoxLoops: it provides loop overloads that iterate over the particles of a ParticleSoA and decorate the inner loop with CD_PRAGMA_SIMD, so elementwise per-particle kernels (hopefully) auto-vectorize. This mirrors BoxLoops exactly, with the cell index replaced by the particle index:

// column pointers captured once, OUTSIDE the loop
ParticleReal* sigma = soa.column<&P::conductivity>(); // payload column -> ParticleReal*
const double* w = soa.weightColumn(); // weight is always double
const ParticleReal* mu = soa.column<&P::mobility>(); // payload column
ParticleLoops::loop(soa, [&](std::size_t i) { sigma[i] = w[i] * mu[i]; });
CD_PARTICLE_REAL ParticleReal
Floating-point type a user may use for payload columns.
Definition CD_ParticleSoA.H:156
ALWAYS_INLINE void loop(const ParticleSoA< P, Traits > &a_soa, Functor &&a_kernel)
Launch a kernel over every particle in a ParticleSoA, decorating the loop with CD_PRAGMA_SIMD.
Definition CD_ParticleLoops.H:87

Why this exists

CD_PRAGMA_SIMD (GCC ivdep / clang vectorize(enable)) tells the compiler to ignore assumed loop-carried/aliasing dependencies, so the kernel vectorizes without the caller having to launder column pointers through __restrict, and without the compiler emitting runtime aliasing checks ("loop versioning"). ALWAYS_INLINE guarantees the kernel is inlined into the loop body.

Contract

Note
As in CD_Decorations.H, CD_PRAGMA_SIMD is disabled in debug builds (when NDEBUG is not defined); the loop is then an ordinary correct loop.