Skip to content

Commit

Permalink
allow the random number generator on GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Sep 14, 2023
1 parent f1811e1 commit 6a61340
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Exec/Make.Castro
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ ifeq ($(USE_CXX_MODEL_PARSER), TRUE)
DEFINES += -DCXX_MODEL_PARSER -DNPTS_MODEL=$(MAX_NPTS_MODEL) -DNUM_MODELS=$(NUM_MODELS)
endif

ifeq ($(USE_RNG_STATE_INIT), TRUE)
DEFINES += -DRNG_STATE_INIT
endif

# add / define any special physics we need

ifeq ($(USE_MHD), TRUE)
Expand Down
1 change: 1 addition & 0 deletions Exec/science/xrb_layered/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USE_GRAV = TRUE
USE_REACT = TRUE

USE_CXX_MODEL_PARSER = TRUE
USE_RNG_STATE_INIT = TRUE

CASTRO_HOME = ../../..

Expand Down
2 changes: 1 addition & 1 deletion Source/driver/Castro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ Castro::initData ()
auto s = S_new[mfi].array();
auto geomdata = geom.data();

#ifdef USE_RNG_STATE_INIT
#ifdef RNG_STATE_INIT
amrex::ParallelForRNG(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept
{
Expand Down
5 changes: 5 additions & 0 deletions Source/driver/Castro_advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ Castro::initialize_advance(Real time, Real dt, int amr_iteration)
auto s = S_old[mfi].array();
auto geomdata = geom.data();

#ifdef RNG_STATE_INIT
amrex::Error("drive initial convection not yet supported for random initialization");
#else
amrex::ParallelFor(box,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
{
Expand All @@ -449,6 +452,8 @@ Castro::initialize_advance(Real time, Real dt, int amr_iteration)
(vx_orig * vx_orig + vy_orig * vy_orig + vz_orig * vz_orig);

});
#endif

}

}
Expand Down
4 changes: 4 additions & 0 deletions Source/driver/Castro_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,17 @@ Castro::restart (Amr& papa,
auto s = S_new[mfi].array();
auto geomdata = geom.data();

#ifdef RNG_STATE_INIT
amrex::Error("Error: random initialization not yet supported with grown factor");
#else
amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
{
// C++ problem initialization; has no effect if not implemented
// by a problem setup (defaults to an empty routine).
problem_initialize_state_data(i, j, k, s, geomdata);
});
#endif
}
}
}
Expand Down

0 comments on commit 6a61340

Please sign in to comment.