From 2bc1322aa76f7026e5b42639bb3d12125da2407c Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Mon, 18 Oct 2021 14:06:08 -0700 Subject: Option to do single precision mesh communication. (#2294) * option to use single precision guard cell exhanges * add missing files * fix namespace issue * change precision of comms to float * ParmParse the single_precision_comms flag * set back to real * test * make sure dst is filled * nGrow -> nGrowVect * restore float * don't override valid cells * single precision mesh * whitespace * wrap SumBoundary * Wrap additional uses of FillBoundary. * catch missing copies of ParallelCopy * missing OverrideSyncs * add wrapper for iMultifab * fix typo * moar typos * typo * strip single_precision_mesh option * fix original copy * update fusible syntax Co-authored-by: Weiqun Zhang * Fix: Single Precision Builds Should not copy around data for `do_single_precision_comms` * Docs: warpx.do_single_precision_comms * initialize this tmp multifab to 0.0 * fix tiny profile label * remove orig copies, they are only correct for FillBoundary * loosen tolerance for space charge tests for single precision * missing some setVal * another missing setVal * missing setVal * add wrapper for new version of sumboundary * add explicit cast to silence compiler warning * add a test for single precision comms * revert change to test precision * add benchmark for single precision comms test * restore tolerance I removed by mistake * tolerance * copyright headers * drop tolerance for single precision tests in default analysis script * missing python module * bump tol again * fix bad merge * Apply suggestions from code review Co-authored-by: Axel Huebl Co-authored-by: Remi Lehe Co-authored-by: Axel Huebl Co-authored-by: Weiqun Zhang --- Source/Parallelization/WarpXCommUtil.cpp | 243 +++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 Source/Parallelization/WarpXCommUtil.cpp (limited to 'Source/Parallelization/WarpXCommUtil.cpp') diff --git a/Source/Parallelization/WarpXCommUtil.cpp b/Source/Parallelization/WarpXCommUtil.cpp new file mode 100644 index 000000000..d395e7628 --- /dev/null +++ b/Source/Parallelization/WarpXCommUtil.cpp @@ -0,0 +1,243 @@ +/* Copyright 2021 Andrew Myers + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#include "WarpXCommUtil.H" + +#include +#include +#include +#include +#include +#include + +namespace WarpXCommUtil { + +void ParallelCopy (amrex::MultiFab& dst, + const amrex::MultiFab& src, + int src_comp, + int dst_comp, + int num_comp, + const amrex::IntVect& src_nghost, + const amrex::IntVect& dst_nghost, + const amrex::Periodicity& period, + amrex::FabArrayBase::CpOp op) +{ + BL_PROFILE("WarpXCommUtil::ParallelCopy"); + + using WarpXCommUtil::comm_float_type; + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > src_tmp(src.boxArray(), + src.DistributionMap(), + num_comp, + src_nghost); + mixedCopy(src_tmp, src, src_comp, 0, num_comp, src_nghost); + + amrex::FabArray > dst_tmp(dst.boxArray(), + dst.DistributionMap(), + num_comp, + dst_nghost); + + mixedCopy(dst_tmp, dst, dst_comp, 0, num_comp, dst_nghost); + + dst_tmp.ParallelCopy(src_tmp, 0, 0, num_comp, + src_nghost, dst_nghost, period, op); + + mixedCopy(dst, dst_tmp, 0, dst_comp, num_comp, dst_nghost); + } + else + { + dst.ParallelCopy(src, src_comp, dst_comp, num_comp, src_nghost, dst_nghost, period, op); + } +} + +void ParallelAdd (amrex::MultiFab& dst, + const amrex::MultiFab& src, + int src_comp, + int dst_comp, + int num_comp, + const amrex::IntVect& src_nghost, + const amrex::IntVect& dst_nghost, + const amrex::Periodicity& period) +{ + WarpXCommUtil::ParallelCopy(dst, src, src_comp, dst_comp, num_comp, src_nghost, dst_nghost, period, + amrex::FabArrayBase::ADD); +} + +void FillBoundary (amrex::MultiFab& mf, const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::FillBoundary"); + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + mf.nComp(), + mf.nGrowVect()); + + mixedCopy(mf_tmp, mf, 0, 0, mf.nComp(), mf.nGrowVect()); + + mf_tmp.FillBoundary(period); + + mixedCopy(mf, mf_tmp, 0, 0, mf.nComp(), mf.nGrowVect()); + } + else + { + mf.FillBoundary(period); + } +} + +void FillBoundary (amrex::MultiFab& mf, + amrex::IntVect ng, + const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::FillBoundary"); + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + mf.nComp(), + mf.nGrowVect()); + + mixedCopy(mf_tmp, mf, 0, 0, mf.nComp(), mf.nGrowVect()); + + mf_tmp.FillBoundary(ng, period); + + mixedCopy(mf, mf_tmp, 0, 0, mf.nComp(), mf.nGrowVect()); + } + else + { + mf.FillBoundary(ng, period); + } +} + +void FillBoundary (amrex::iMultiFab& imf, const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::FillBoundary"); + + imf.FillBoundary(period); +} + +void FillBoundary (amrex::iMultiFab& imf, + amrex::IntVect ng, + const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::FillBoundary"); + imf.FillBoundary(ng, period); +} + +void +FillBoundary (amrex::Vector const& mf, const amrex::Periodicity& period) +{ + for (auto x : mf) { + WarpXCommUtil::FillBoundary(*x, period); + } +} + +void SumBoundary (amrex::MultiFab& mf, const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::SumBoundary"); + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + mf.nComp(), + mf.nGrowVect()); + + mixedCopy(mf_tmp, mf, 0, 0, mf.nComp(), mf.nGrowVect()); + + mf_tmp.SumBoundary(period); + + mixedCopy(mf, mf_tmp, 0, 0, mf.nComp(), mf.nGrowVect()); + } + else + { + mf.SumBoundary(period); + } +} + +void SumBoundary (amrex::MultiFab& mf, + int start_comp, + int num_comps, + amrex::IntVect ng, + const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::SumBoundary"); + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + num_comps, + ng); + mixedCopy(mf_tmp, mf, start_comp, 0, num_comps, ng); + + mf_tmp.SumBoundary(0, num_comps, ng, period); + + mixedCopy(mf, mf_tmp, 0, start_comp, num_comps, ng); + } + else + { + mf.SumBoundary(start_comp, num_comps, ng, period); + } +} + +void SumBoundary (amrex::MultiFab& mf, + int start_comp, + int num_comps, + amrex::IntVect src_ng, + amrex::IntVect dst_ng, + const amrex::Periodicity& period) +{ + BL_PROFILE("WarpXCommUtil::SumBoundary"); + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + num_comps, + mf.nGrowVect()); + mixedCopy(mf_tmp, mf, start_comp, 0, num_comps, mf.nGrowVect()); + + mf_tmp.SumBoundary(0, num_comps, src_ng, dst_ng, period); + + mixedCopy(mf, mf_tmp, 0, start_comp, num_comps, dst_ng); + } + else + { + mf.SumBoundary(start_comp, num_comps, src_ng, dst_ng, period); + } +} + +void OverrideSync (amrex::MultiFab& mf, + const amrex::Periodicity& period) +{ + if (mf.ixType().cellCentered()) return; + + if (WarpX::do_single_precision_comms) + { + amrex::FabArray > mf_tmp(mf.boxArray(), + mf.DistributionMap(), + mf.nComp(), + mf.nGrowVect()); + + mixedCopy(mf_tmp, mf, 0, 0, mf.nComp(), mf.nGrowVect()); + + auto msk = mf.OwnerMask(period); + amrex::OverrideSync(mf_tmp, *msk, period); + + mixedCopy(mf, mf_tmp, 0, 0, mf.nComp(), mf.nGrowVect()); + } + else + { + mf.OverrideSync(period); + } +} + +} -- cgit v1.2.3