-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for multiple periods in FillBoundary and ParallelCopy (#4106)
This is a feature requested by a user who wants to run simulations with the number of ghost cells more than the domain length in periodic directions.
- Loading branch information
1 parent
b05f69f
commit 12002e7
Showing
8 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
foreach(D IN LISTS AMReX_SPACEDIM) | ||
set(_sources main.cpp) | ||
set(_input_files ) | ||
|
||
setup_test(${D} _sources _input_files) | ||
|
||
unset(_sources) | ||
unset(_input_files) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
AMREX_HOME := ../.. | ||
|
||
DEBUG = FALSE | ||
|
||
DIM = 3 | ||
|
||
COMP = gcc | ||
|
||
USE_MPI = FALSE | ||
USE_OMP = FALSE | ||
USE_CUDA = FALSE | ||
USE_HIP = FALSE | ||
USE_SYCL = FALSE | ||
|
||
BL_NO_FORT = TRUE | ||
|
||
TINY_PROFILE = FALSE | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.defs | ||
|
||
include ./Make.package | ||
include $(AMREX_HOME)/Src/Base/Make.package | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CEXE_sources += main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <AMReX.H> | ||
#include <AMReX_Geometry.H> | ||
#include <AMReX_FabArray.H> | ||
#include <AMReX_MFParallelFor.H> | ||
#include <AMReX_ParReduce.H> | ||
|
||
using namespace amrex; | ||
|
||
int main (int argc, char* argv[]) | ||
{ | ||
amrex::Initialize(argc, argv); | ||
{ | ||
// Domain size: 2 x 128 x 4 | ||
Box box(IntVect(0), IntVect(AMREX_D_DECL(1, 127, 3))); | ||
Array<int,AMREX_SPACEDIM> is_periodic{AMREX_D_DECL(1,1,1)}; | ||
Geometry geom(box, RealBox(AMREX_D_DECL(Real(0),Real(0),Real(0)), | ||
AMREX_D_DECL(Real(1),Real(1),Real(1))), | ||
CoordSys::cartesian, is_periodic); | ||
BoxArray ba(box); | ||
ba.maxSize(32); | ||
ba.convert(IntVect(AMREX_D_DECL(1,0,0))); // nodal in x-direction | ||
DistributionMapping dm(ba); | ||
|
||
FabArray<BaseFab<Long>> mf1(ba,dm,1,IntVect(4)); | ||
FabArray<BaseFab<Long>> mf2(ba,dm,1,IntVect(5)); | ||
|
||
mf1.setVal(-1); | ||
mf2.setVal(-2); | ||
|
||
auto const& len = geom.Domain().length3d(); | ||
auto expected = [=] AMREX_GPU_DEVICE (int i, int j, int k) | ||
{ | ||
while (i < 0 ) { i += len[0]; } | ||
while (i >= len[0]) { i -= len[0]; } | ||
while (j < 0 ) { j += len[1]; } | ||
while (j >= len[1]) { j -= len[1]; } | ||
while (k < 0 ) { k += len[2]; } | ||
while (k >= len[2]) { k -= len[2]; } | ||
return Long(i) + Long(j)*Long(len[0]) + Long(k)*Long(len[0])*Long(len[1]); | ||
}; | ||
|
||
auto const& ma1 = mf1.arrays(); | ||
auto const& ma2 = mf2.arrays(); | ||
|
||
// Initialize valid region | ||
ParallelFor(mf1, IntVect(0), [=] AMREX_GPU_DEVICE (int b, int i, int j, int k) | ||
{ | ||
ma1[b](i,j,k) = expected(i,j,k); | ||
}); | ||
|
||
mf1.FillBoundary(geom.periodicity()); | ||
mf2.ParallelCopy(mf1, 0, 0, 1, IntVect(0), mf2.nGrowVect(), geom.periodicity()); | ||
|
||
auto r1 = ParReduce(TypeList<ReduceOpSum>{}, TypeList<Long>{}, mf1, mf1.nGrowVect(), | ||
[=] AMREX_GPU_DEVICE (int b, int i, int j, int k) -> GpuTuple<Long> | ||
{ | ||
return { Long(expected(i,j,k) != ma1[b](i,j,k)) }; | ||
}); | ||
auto r2 = ParReduce(TypeList<ReduceOpSum>{}, TypeList<Long>{}, mf2, mf2.nGrowVect(), | ||
[=] AMREX_GPU_DEVICE (int b, int i, int j, int k) -> GpuTuple<Long> | ||
{ | ||
return { Long(expected(i,j,k) != ma2[b](i,j,k)) }; | ||
}); | ||
|
||
AMREX_ALWAYS_ASSERT(r1 == 0); | ||
AMREX_ALWAYS_ASSERT(r2 == 0); | ||
|
||
if (r1 == 0 && r2 == 0) { | ||
amrex::Print() << "SUCCESS\n"; | ||
} | ||
} | ||
amrex::Finalize(); | ||
} |