aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/WarpXParticleContainer.cpp
diff options
context:
space:
mode:
authorGravatar Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> 2023-06-29 22:54:07 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-30 05:54:07 +0000
commit5baa09ceadc6291f67839c7842fd1756edfc1186 (patch)
tree6acf8181878c23142ce18006a2c084b173a8d2c2 /Source/Particles/WarpXParticleContainer.cpp
parentb47641c1df0c5ca10527d2163ffb50d02e206821 (diff)
downloadWarpX-5baa09ceadc6291f67839c7842fd1756edfc1186.tar.gz
WarpX-5baa09ceadc6291f67839c7842fd1756edfc1186.tar.zst
WarpX-5baa09ceadc6291f67839c7842fd1756edfc1186.zip
Use GPU compatible kernel in `sumParticleCharge` (#3949)
* use GPU compatible kernel in `sumParticleCharge` * Add omp threading if GPU is not used. Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov> --------- Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
Diffstat (limited to 'Source/Particles/WarpXParticleContainer.cpp')
-rw-r--r--Source/Particles/WarpXParticleContainer.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp
index 8abe012a0..7775702e4 100644
--- a/Source/Particles/WarpXParticleContainer.cpp
+++ b/Source/Particles/WarpXParticleContainer.cpp
@@ -1125,23 +1125,27 @@ WarpXParticleContainer::GetChargeDensity (int lev, bool local)
amrex::ParticleReal WarpXParticleContainer::sumParticleCharge(bool local) {
amrex::ParticleReal total_charge = 0.0;
+ ReduceOps<ReduceOpSum> reduce_op;
+ ReduceData<ParticleReal> reduce_data(reduce_op);
const int nLevels = finestLevel();
- for (int lev = 0; lev <= nLevels; ++lev)
- {
#ifdef AMREX_USE_OMP
-#pragma omp parallel reduction(+:total_charge)
+#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
+ for (int lev = 0; lev <= nLevels; ++lev) {
for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti)
{
- auto& wp = pti.GetAttribs(PIdx::w);
- for (const auto& ww : wp) {
- total_charge += ww;
- }
+ const auto wp = pti.GetAttribs(PIdx::w).data();
+
+ reduce_op.eval(pti.numParticles(), reduce_data,
+ [=] AMREX_GPU_DEVICE (int ip)
+ { return wp[ip]; });
}
}
+ total_charge = get<0>(reduce_data.value());
+
if (local == false) ParallelDescriptor::ReduceRealSum(total_charge);
total_charge *= this->charge;
return total_charge;