![]() |
Block-Structured AMR Software Framework
|
General purpose utilities. More...
Namespaces | |
| namespace | amrex::Font |
| ANSI font-style escape codes (bold, italic, underline, etc.). | |
| namespace | amrex::FGColor |
| ANSI foreground-color escape codes. | |
| namespace | amrex::BGColor |
| ANSI background-color escape codes. | |
| namespace | amrex::PhysBCType |
| Physical boundary condition types assigned to domain faces. | |
| namespace | amrex::BCType |
| Mathematical boundary condition types applied per face. | |
Classes | |
| struct | amrex::Plus< T > |
| Function object that returns the sum of two values. More... | |
| struct | amrex::Minus< T > |
| Function object that returns the difference of two values. More... | |
| struct | amrex::Minimum< T > |
| Function object that returns the smaller of two values. More... | |
| struct | amrex::Maximum< T > |
| Function object that returns the larger of two values. More... | |
| struct | amrex::LogicalAnd< T > |
| Function object that returns the logical AND of two values. More... | |
| struct | amrex::LogicalOr< T > |
| Function object that returns the logical OR of two values. More... | |
| struct | amrex::Multiplies< T > |
| Function object that returns the product of two values. More... | |
| struct | amrex::Divides< T > |
| Function object that returns the quotient of two values. More... | |
| class | amrex::ParmParse |
| Parse Parameters From Command Line and Input Files. More... | |
| class | amrex::IParser |
| Integer-only variant of amrex::Parser. More... | |
| class | amrex::Parser |
| Front-end for parsing scalar expressions into GPU/CPU executors. More... | |
| class | amrex::Any |
Type-erased container similar to std::any, but supports move-only types. More... | |
| class | amrex::BackgroundThread |
| Utility class running deferred work on a single background thread. More... | |
| class | amrex::BCRec |
| Boundary condition record storing low/high face types per coordinate. More... | |
Macros | |
| #define | AMREX_ENUM(CLASS, ...) |
| Declare a scoped enum with reflection support. | |
Typedefs | |
| using | amrex::RuntimeError = std::runtime_error |
Functions | |
| template<class T > | |
| __host__ __device__ constexpr const T & | amrex::min (const T &a, const T &b) noexcept |
| template<class T , class ... Ts> | |
| __host__ __device__ constexpr const T & | amrex::min (const T &a, const T &b, const Ts &... c) noexcept |
| template<class T > | |
| __host__ __device__ constexpr const T & | amrex::max (const T &a, const T &b) noexcept |
| template<class T , class ... Ts> | |
| __host__ __device__ constexpr const T & | amrex::max (const T &a, const T &b, const Ts &... c) noexcept |
| template<class T > | |
| __host__ __device__ constexpr T | amrex::elemwiseMin (T const &a, T const &b) noexcept |
| template<class T , class ... Ts> | |
| __host__ __device__ constexpr T | amrex::elemwiseMin (const T &a, const T &b, const Ts &... c) noexcept |
| template<class T > | |
| __host__ __device__ constexpr T | amrex::elemwiseMax (T const &a, T const &b) noexcept |
| template<class T , class ... Ts> | |
| __host__ __device__ constexpr T | amrex::elemwiseMax (const T &a, const T &b, const Ts &... c) noexcept |
| template<typename T > | |
| __host__ __device__ void | amrex::Swap (T &t1, T &t2) noexcept |
| template<typename T > | |
| __host__ __device__ constexpr const T & | amrex::Clamp (const T &v, const T &lo, const T &hi) |
| template<std::floating_point T> | |
| __host__ __device__ bool | amrex::almostEqual (T x, T y, int ulp=2) |
| template<std::floating_point T, class F > | |
| __host__ __device__ T | amrex::bisect (T lo, T hi, F f, T tol=1e-12, int max_iter=100) |
| Find a root of a scalar function on a bracketing interval using bisection. | |
| template<typename T , std::integral I> | |
| __host__ __device__ I | amrex::bisect (T const *d, I lo, I hi, T const &v) |
| Find the index of the interval containing a value in a sorted array. | |
| template<typename ItType , typename ValType > | |
| __host__ __device__ ItType | amrex::upper_bound (ItType first, ItType last, const ValType &val) |
| Return an iterator to the first element greater than a given value. | |
| template<typename ItType , typename ValType > | |
| __host__ __device__ ItType | amrex::lower_bound (ItType first, ItType last, const ValType &val) |
| Return an iterator to the first element not less than a given value. | |
| template<typename ItType , std::floating_point ValType> requires (std::floating_point<typename std::iterator_traits<ItType>::value_type>) | |
| __host__ __device__ void | amrex::linspace (ItType first, const ItType &last, const ValType &start, const ValType &stop) |
| Fill a range with linearly spaced values over a closed interval. | |
| template<typename ItType , std::floating_point ValType> requires (std::floating_point<typename std::iterator_traits<ItType>::value_type>) | |
| __host__ __device__ void | amrex::logspace (ItType first, const ItType &last, const ValType &start, const ValType &stop, const ValType &base) |
| Fill a range with logarithmically spaced values over a closed interval. | |
| template<auto I, auto N, class F > | |
| __host__ __device__ constexpr void | amrex::constexpr_for (F const &f) |
Compile-time unrolled loop from I (inclusive) to N (exclusive). | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| std::vector< std::pair< std::string, T > > const & | amrex::getEnumNameValuePairs () |
| Return all (name, value) pairs for an AMREX_ENUM-declared enum type. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| T | amrex::getEnum (std::string_view const &s) |
| Convert a string to an enum value. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| T | amrex::getEnumCaseInsensitive (std::string_view const &s) |
| Convert a string case-insensitively to an enum value. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| std::string | amrex::getEnumNameString (T const &v) |
| Get the name string of an enum value. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| std::vector< std::string > | amrex::getEnumNameStrings () |
| Return a list of all enumerator name strings for an AMREX_ENUM-declared type. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| std::string | amrex::getEnumClassName () |
| Return the class name string of an AMREX_ENUM-declared enum type. | |
| template<typename T , typename ET = amrex_enum_traits<T>> requires (ET::value) | |
| constexpr auto | amrex::toUnderlying (T v) noexcept |
| Return the underlying integer value of an enum enumerator. | |
| Real | amrex::Random () |
| Generate a psuedo-random real from uniform distribution. | |
| __host__ __device__ Real | amrex::Random (RandomEngine const &random_engine) |
| Real | amrex::RandomPositive () |
| Generate a pseudo-random real from uniform distribution, excluding zero. | |
| __host__ __device__ Real | amrex::RandomPositive (RandomEngine const &random_engine) |
| Real | amrex::RandomNormal (Real mean, Real stddev) |
| Generate a psuedo-random real from a normal distribution. | |
| __host__ __device__ Real | amrex::RandomNormal (Real mean, Real stddev, RandomEngine const &random_engine) |
| unsigned int | amrex::RandomPoisson (Real lambda) |
| Generate a psuedo-random integer from a Poisson distribution. | |
| __host__ __device__ unsigned int | amrex::RandomPoisson (Real lambda, RandomEngine const &random_engine) |
| Real | amrex::RandomGamma (Real alpha, Real beta) |
| Generate a psuedo-random floating point number from the Gamma distribution. | |
| __host__ __device__ Real | amrex::RandomGamma (Real alpha, Real beta, RandomEngine const &random_engine) |
| unsigned int | amrex::Random_int (unsigned int n) |
| Generates one pseudorandom unsigned integer which is uniformly distributed on [0,n-1]-interval for each call. For the special case of n = 0, it returns 0. | |
| __host__ __device__ unsigned int | amrex::Random_int (unsigned int n, RandomEngine const &random_engine) |
| ULong | amrex::Random_long (ULong n) |
| Generates one pseudorandom unsigned long which is uniformly distributed on [0,n-1]-interval for each call. For the special case of n = 0, it returns 0. | |
| void | amrex::FillRandom (Real *p, Long N) |
| void | amrex::FillRandomNormal (Real *p, Long N, Real mean, Real stddev) |
| void | amrex::InitRandom (ULong cpu_seed, int nprocs=ParallelDescriptor::NProcs(), ULong gpu_seed=detail::DefaultGpuSeed()) |
| Set the seed of the random number generator. | |
| void | amrex::ResetRandomSeed (ULong cpu_seed, ULong gpu_seed=detail::DefaultGpuSeed()) |
| void | amrex::SaveRandomState (std::ostream &os) |
| Save host random state. | |
| void | amrex::RestoreRandomState (std::istream &is, int nthreads_old, int nstep_old) |
| Restore host random state saved by SaveRandomState. | |
| void | amrex::UniqueRandomSubset (Vector< int > &uSet, int setSize, int poolSize, bool printSet=false) |
| Create a unique subset of random numbers from a pool of integers in the range [0, poolSize - 1] the set will be in the order they are found setSize must be <= poolSize uSet will be resized to setSize if you want all processors to have the same set, call this on one processor and broadcast the array. | |
Variables | |
| constexpr char | amrex::ResetDisplay [] = "\033[0m" |
General purpose utilities.
This topic covers general purpose utilities used throughout AMReX and AMReX applications.
Central capabilities include:
| #define AMREX_ENUM | ( | CLASS, | |
| ... | |||
| ) |
Declare a scoped enum with reflection support.
Defines enum class CLASS : int and registers its enumerator names so that amrex::getEnum, amrex::getEnumCaseInsensitive, amrex::getEnumNameString, and related utilities can convert between strings and values at run time.
Example:
| using amrex::RuntimeError = typedef std::runtime_error |
Exception type used when AMReX is configured to throw on fatal errors.
|
inline |
Return true when the difference between x and y is small, as measured by the given ulp (units in the last place).
|
inline |
Find the index of the interval containing a value in a sorted array.
Find index i in the range [lo,hi) that d[i] <= v < d[i+1]. It is assumed that the input data is sorted. The elements d[lo] and d[hi] are never accessed, so that d only needs to be valid in the exclusive range (lo,hi). It is not checked whether the value v is out-of-bounds. In that case, if v < d[lo], lo is returned, and if v >= d[hi], hi-1 is returned. Note that this is different from std::lower_bound that searches for the first element which is not less than v.
| T | value type. |
| I | integral index type. |
| d | pointer to a sorted array of values. |
| lo | inclusive lower bound of the search range. |
| hi | exclusive upper bound of the search range. |
| v | value to be located. |
i such that d[i] <= v < d[i+1], with lo <= i < hi.
|
inline |
Find a root of a scalar function on a bracketing interval using bisection.
Invalid bracketing and iteration failures are checked with AMReX assertions when assertions are enabled.
| T | floating-point type |
| F | callable type of the scalar function |
| lo | lower bound |
| hi | upper bound |
| f | scalar function |
| tol | absolute tolerance. Iteration stops when hi-lo < tol or when almostEqual(lo,hi) returns true. |
| max_iter | maximum number of bisection iterations allowed. |
|
inlineconstexpr |
Return the reference to lo if v < lo; return the reference to hi if hi < v; otherwise return the reference to v. This function was added to AMReX before switching to C++17. std::clamp can now be used directly instead.
|
inlineconstexpr |
Compile-time unrolled loop from I (inclusive) to N (exclusive).
Approximates the compile-time unrolling of:
The body f is a callable (typically a lambda) that accepts a single integral argument. This can be used inside GPU kernels.
| I | Starting index (compile-time constant). |
| N | One-past-end index (compile-time constant). |
| F | Callable type; must accept an integral argument. |
| f | Callable invoked for each index from I to N-1. |
|
inlineconstexprnoexcept |
Return the element-wise maximum of a, b, and the remaining arguments in c.
|
inlineconstexprnoexcept |
Return the element-wise maximum of a and b for types like XDim3.
|
inlineconstexprnoexcept |
Return the element-wise minimum of a, b, and the rest of the pack c.
|
inlineconstexprnoexcept |
Return the element-wise minimum of a and b for types like XDim3.
Fill random numbers from uniform distribution. The interval is not uniform across backends the way amrex::Random and amrex::RandomPositive are: it is [0,1) on the CPU, but the GPU paths hand back whatever the vendor bulk generator produces, nominally [0,1) for SYCL and (0,1] for CUDA and HIP. Code that depends on either endpoint should guard the values it reads back, or draw with amrex::Random / amrex::RandomPositive instead.
Fill random numbers from normal distribution
| T amrex::getEnum | ( | std::string_view const & | s | ) |
Convert a string to an enum value.
Throws std::runtime_error if s does not match any enumerator name.
Example:
| T amrex::getEnumCaseInsensitive | ( | std::string_view const & | s | ) |
Convert a string case-insensitively to an enum value.
Same as getEnum<T>, but uses a case-insensitive match.
Example:
| std::string amrex::getEnumClassName | ( | ) |
Return the class name string of an AMREX_ENUM-declared enum type.
| T | An enum type declared with AMREX_ENUM. |
| std::string amrex::getEnumNameString | ( | T const & | v | ) |
Get the name string of an enum value.
Throws std::runtime_error if v has no matching enumerator name.
Example:
| std::vector< std::string > amrex::getEnumNameStrings | ( | ) |
Return a list of all enumerator name strings for an AMREX_ENUM-declared type.
| T | An enum type declared with AMREX_ENUM. |
| std::vector< std::pair< std::string, T > > const & amrex::getEnumNameValuePairs | ( | ) |
Return all (name, value) pairs for an AMREX_ENUM-declared enum type.
The result is cached the first time it is called for a given type T.
| T | An enum type declared with AMREX_ENUM. |
| void amrex::InitRandom | ( | ULong | cpu_seed, |
| int | nprocs = ParallelDescriptor::NProcs(), |
||
| ULong | gpu_seed = detail::DefaultGpuSeed() |
||
| ) |
Set the seed of the random number generator.
There is also an entry point for Fortran callable as:
INTEGER seed call blutilinitrand(seed)
or
INTEGER seed call blinitrand(seed)
| __host__ __device__ void amrex::linspace | ( | ItType | first, |
| const ItType & | last, | ||
| const ValType & | start, | ||
| const ValType & | stop | ||
| ) |
Fill a range with linearly spaced values over a closed interval.
This function assigns linearly spaced floating-point values to the range [first, last), starting at start and ending at stop. The value range is inclusive at both ends such that the first element is set to start and the last element to stop exactly. Note that this function does nothing when the range contains fewer than two elements (i.e., last-first < 2).
| ItType | iterator type. |
| ValType | floating-point value type. |
| first | pointing to the first element of the output range. |
| last | pointing one past the last element of the output range. |
| start | start value. |
| stop | stop value. |
| __host__ __device__ void amrex::logspace | ( | ItType | first, |
| const ItType & | last, | ||
| const ValType & | start, | ||
| const ValType & | stop, | ||
| const ValType & | base | ||
| ) |
Fill a range with logarithmically spaced values over a closed interval.
This function assigns logarithmically spaced floating-point values to the range [first, last), starting at base^start and ending at base^stop. The value range is inclusive at both ends such that the first element is set to base^start and the last element to base^stop exactly. Note that this function does nothing when the range contains fewer than two elements (i.e., last-first < 2).
| ItType | iterator type. |
| ValType | floating-point value type. |
| first | pointing to the first element of the output range. |
| last | pointing one past the last element of the output range. |
| start | start value. |
| stop | stop value. |
| base | base of the exponential. |
| __host__ __device__ ItType amrex::lower_bound | ( | ItType | first, |
| ItType | last, | ||
| const ValType & | val | ||
| ) |
Return an iterator to the first element not less than a given value.
This function is an implementation of std::lower_bound that works on both host and device.
| ItType | iterator type. |
| ValType | value type. |
| first | inclusive lower bound of the search range. |
| last | exclusive upper bound of the search range. |
| val | value to compare the elements to. |
val.
|
inlineconstexprnoexcept |
Return the greater value. This function was added to AMReX to support GPU before std::max was constexpr in C++14. std::max can now be used directly instead.
|
inlineconstexprnoexcept |
Return the greatest value. This function was added to AMReX to support GPU before std::max was constexpr in C++14. std::max can now be used directly instead.
|
inlineconstexprnoexcept |
Return the smaller value. This function was added to AMReX to support GPU before std::min was constexpr in C++14. std::min can now be used directly instead.
|
inlineconstexprnoexcept |
Return the smallest value. This function was added to AMReX to support GPU before std::min was constexpr in C++14. std::min can now be used directly instead.
| Real amrex::Random | ( | ) |
Generate a psuedo-random real from uniform distribution.
Generates one pseudorandom real number from a uniform distribution between 0.0 and 1.0 (0.0 included, 1.0 excluded).
1 - amrex::Random(), which is not equivalent: it costs an arithmetic operation and discards resolution, because the subtraction is exact only above 0.5 and collapses smaller values onto a coarse grid.
|
inline |
Generates one pseudorandom unsigned integer which is uniformly distributed on [0,n-1]-interval for each call. For the special case of n = 0, it returns 0.
The CPU version of this function uses C++11's mt19937. The GPU version uses CURAND's XORWOW generator.
|
inline |
Generates one pseudorandom unsigned long which is uniformly distributed on [0,n-1]-interval for each call. For the special case of n = 0, it returns 0.
The CPU version of this function uses C++11's mt19937. There is no GPU version.
Generate a psuedo-random floating point number from the Gamma distribution.
Generates one real number (single or double) extracted from a Gamma distribution, given the Real parameters alpha and beta. alpha and beta must both be > 0. The CPU version of this function relies on the Standard Template Library. The GPU version is implemented in terms of amrex::RandomPositive and amrex::RandomNormal.
|
inline |
Generate a psuedo-random real from a normal distribution.
Generates one pseudorandom real number from a normal distribution with mean 'mean' and standard deviation 'stddev'.
|
inline |
Generate a psuedo-random integer from a Poisson distribution.
Generates one pseudorandom positive integer number extracted from a Poisson distribution, given the Real parameter lambda. The CPU version of this function relies on the standard Template Library The GPU version of this function relies on the cuRAND library
|
inline |
| Real amrex::RandomPositive | ( | ) |
Generate a pseudo-random real from uniform distribution, excluding zero.
Generates one pseudorandom real number from a uniform distribution between 0.0 and 1.0 (0.0 excluded, 1.0 included).
This is the counterpart to amrex::Random for samplers that are singular at zero, for example
Prefer this over deriving a non-zero value from amrex::Random by hand with 1 - amrex::Random(), which is lossier for no benefit. See the note on amrex::Random.
There is no accuracy or performance penalty for choosing this interval over the half-open [0,1) of amrex::Random. On CUDA/HIP it is the native interval of the underlying generator, so the value is returned as drawn; on the host and with SYCL the generator is natively [0,1) and only its zero endpoint is relocated to one. No arithmetic is performed on any path, so no resolution is lost and there is nothing that a floating-point mode could change: the exclusion of zero holds under -ffast-math / –use_fast_math and flush-to-zero alike, because it is established by a comparison rather than by a computed bound.
The smallest value that can be returned is in every case the smallest positive value of the underlying generator, and is therefore backend-dependent: roughly 2^-33 in single precision with curand, 2^-32 with rocrand, and the granularity of the standard library's distribution on the host, which for a 32-bit engine is 2^-32 in single precision and 2^-64 in double. All of these are normal numbers, so flush-to-zero cannot reach them.
|
inline |
Restore host random state saved by SaveRandomState.
This does not restore GPU random state used by ParallelForRNG or GPU FillRandom/FillRandomNormal calls.
| void amrex::SaveRandomState | ( | std::ostream & | os | ) |
Save host random state.
This function only serializes the host-side random number generators used by the host random-number APIs. It does not save GPU random state used by ParallelForRNG or GPU FillRandom/FillRandomNormal calls.
|
inlinenoexcept |
Swap the contents of t1 and t2. std::swap can be used directly instead in GPU codes since C++20.
|
constexprnoexcept |
Return the underlying integer value of an enum enumerator.
Useful when building bitmasks.
Create a unique subset of random numbers from a pool of integers in the range [0, poolSize - 1] the set will be in the order they are found setSize must be <= poolSize uSet will be resized to setSize if you want all processors to have the same set, call this on one processor and broadcast the array.
| __host__ __device__ ItType amrex::upper_bound | ( | ItType | first, |
| ItType | last, | ||
| const ValType & | val | ||
| ) |
Return an iterator to the first element greater than a given value.
This function is an implementation of std::upper_bound that works on both host and device.
| ItType | iterator type. |
| ValType | value type. |
| first | inclusive lower bound of the search range. |
| last | exclusive upper bound of the search range. |
| val | value to compare the elements to. |
val.
|
constexpr |
Reset all display attributes to terminal defaults.