From fdcbb7a0152baf96e81a500035fd139e9c11f40c Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Wed, 15 Mar 2023 13:58:18 -0700 Subject: [PATCH] Add assert that we are not inside threaded region when InitRandom is called. (#3204) --- Src/Base/AMReX_Random.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Src/Base/AMReX_Random.cpp b/Src/Base/AMReX_Random.cpp index b2c754ea287..135c5391ebf 100644 --- a/Src/Base/AMReX_Random.cpp +++ b/Src/Base/AMReX_Random.cpp @@ -67,6 +67,12 @@ InitRandom (ULong cpu_seed, int nprocs, ULong gpu_seed) nthreads = OpenMP::get_max_threads(); generators.resize(nthreads); +#ifdef AMREX_USE_OMP + if (omp_in_parallel()) { + amrex::Abort("It is not safe to call amrex::InitRandom inside a threaded region."); + } +#endif + #ifdef AMREX_USE_OMP #pragma omp parallel #endif