Skip to content

Commit

Permalink
Avoid self copy in MultiFab::Copy (AMReX-Codes#3986)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jun 14, 2024
1 parent dad25a4 commit 7eb6170
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Src/Base/AMReX_FabArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ Copy (FabArray<DFAB>& dst, FabArray<SFAB> const& src, int srccomp, int dstcomp,

using DT = typename DFAB::value_type;

if (dst.local_size() == 0) { return; }

// avoid self copy
if constexpr (std::is_same_v<typename SFAB::value_type, typename DFAB::value_type>) {
if (dst.atLocalIdx(0).dataPtr(dstcomp) == src.atLocalIdx(0).dataPtr(srccomp)) {
return;
}
}

#ifdef AMREX_USE_GPU
if (Gpu::inLaunchRegion() && dst.isFusingCandidate()) {
auto const& srcarr = src.const_arrays();
Expand Down

0 comments on commit 7eb6170

Please sign in to comment.