3#include <AMReX_Config.H>
44 template <
typename T>
bool is_it (std::string
const& s, T& v);
47 const std::vector<std::string>&
Tokenize (
const std::string& instr,
48 const std::string& separators);
76 bool verbose =
false);
92 bool callbarrier =
true);
96 bool callbarrier =
true);
100 bool callbarrier =
true);
151 const Vector<int> &refratios);
160 explicit expect (std::string str_);
161 explicit expect (
const char* istr_);
163 [[nodiscard]]
const std::string&
the_string( )
const;
171 StreamRetry(std::ostream &os, std::string suffix,
int maxtries);
172 StreamRetry(std::string filename,
bool abortonretryfailure,
int maxtries);
180 bool abortOnRetryFailure =
true;
181 std::string fileName;
183 std::ostream::pos_type spos;
186 static int nStreamErrors;
191 void SyncStrings(
const Vector<std::string> &localStrings,
192 Vector<std::string> &syncedStrings,
bool &alreadySynced);
200 static const Long gcc_map_node_extra_bytes = 32L;
203 template <
typename Key,
typename T,
class Compare>
amrex::Long bytesOf (
const std::map<Key,T,Compare>& m);
210 template<
class T>
void BroadcastArray(Vector<T> &aT,
int myLocalId,
int rootId,
const MPI_Comm &localComm);
212 void Sleep (
double sleepsec);
216 std::chrono::high_resolution_clock,
217 std::chrono::steady_clock>;
218 double second () noexcept;
220 template<typename T>
void hash_combine (uint64_t & seed, const T & val) noexcept;
221 template<typename T> uint64_t
hash_vector (const
Vector<T> & vec, uint64_t seed = 0xDEADBEEFDEADBEEF) noexcept;
224 std::ostream&
ToString(std::ostream& os,
226 const
char* symbol_begin = "[",
227 const
char* symbol_delim = ", ",
228 const
char* symbol_end = "]",
229 const
char* symbol_str = "\"",
234 const
char* symbol_begin = "[",
235 const
char* symbol_delim = ", ",
236 const
char* symbol_end = "]",
237 const
char* symbol_str = "\"",
239 std::ostringstream ss = std::ostringstream{});
250 template <
typename F,
typename... T>
253 ->
decltype(std::declval<F>()(std::declval<T>()...));
259 std::istringstream ss(s);
262 std::getline(ss, left);
272 if(myLocalId == rootId) {
275 ParallelDescriptor::Bcast(&aT_Size, 1, rootId, localComm);
277 if(myLocalId != rootId) {
281 ParallelDescriptor::Bcast(aT.
dataPtr(), aT.
size(), rootId, localComm);
297#define BL_LANG_FORT 1
300#ifdef BL_FORT_USE_UNDERSCORE
301#undef BL_FORT_USE_UNDERSCORE
310#define BL_FORT_USE_UNDERSCORE 1
313#ifdef BL_FORT_USE_UPPERCASE
314#undef BL_FORT_USE_UPPERCASE
323#define BL_FORT_USE_UPPERCASE 1
326#ifdef BL_FORT_USE_LOWERCASE
327#undef BL_FORT_USE_LOWERCASE
336#define BL_FORT_USE_LOWERCASE 1
348#define BL_IGNORE_MAX 100000
354 return sizeof(v) + v.capacity()*
sizeof(T);
357template <
typename Key,
typename T,
class Compare>
361 return sizeof(m) + m.size()*(
sizeof(Key)+
sizeof(T)+gcc_map_node_extra_bytes);
399 seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed<<6) + (seed>>2);
406 for (
const auto &
x: vec) {
413namespace amrex::detail {
417 constexpr decltype((std::declval<T>().begin(), std::declval<T>().end(),
true)) HasBeginEnd() {
420 template <
class T,
class... Args>
421 constexpr bool HasBeginEnd(Args...) {
427 constexpr decltype((std::tuple_size<T>::value,
true)) HasTupleSize() {
430 template <
class T,
class... Args>
431 constexpr bool HasTupleSize(Args...) {
436 template <
class T, std::size_t... idx>
437 void ToStringTupleImp(std::index_sequence<idx...>, std::ostream& os,
const T& t,
438 const char* symbol_begin,
const char* symbol_delim,
439 const char* symbol_end,
const char* symbol_str,
int limit) {
442 auto op = [&](
auto& value) {
443 if (count > 0 && (count <= limit || limit < 0)) {
446 if (count < limit || limit < 0) {
447 ToString(os, value, symbol_begin, symbol_delim, symbol_end,
449 }
else if (count == limit) {
454 (op(std::get<idx>(t)), ...);
462 const char* symbol_delim,
const char* symbol_end,
463 const char* symbol_str,
int limit)
465 if constexpr (std::is_same_v<std::string, T> ||
466 std::is_same_v<std::string_view, T> ||
467 std::is_same_v<char*, std::decay_t<T>> ||
468 std::is_same_v<const char*, T>) {
470 os << symbol_str << t << symbol_str;
471 }
else if constexpr (std::is_same_v<signed char, T> ||
472 std::is_same_v<unsigned char, T>) {
474 os << static_cast<int>(t);
475 }
else if constexpr (std::is_pointer_v<T>) {
477 os << static_cast<const void*>(t);
478 }
else if constexpr (detail::HasBeginEnd<T>() || std::is_array_v<T>) {
482 for (
auto& value : t) {
486 if (count < limit || limit < 0) {
487 ToString(os, value, symbol_begin, symbol_delim, symbol_end,
489 }
else if (count == limit) {
496 }
else if constexpr (detail::HasTupleSize<T>()) {
498 detail::ToStringTupleImp(std::make_index_sequence<std::tuple_size_v<T>>{},
499 os, t, symbol_begin, symbol_delim, symbol_end,
509std::string
amrex::ToString(
const T& t,
const char* symbol_begin,
const char* symbol_delim,
510 const char* symbol_end,
const char* symbol_str,
511 int limit, std::ostringstream ss)
513 ToString(ss, t, symbol_begin, symbol_delim, symbol_end, symbol_str, limit);
517template <
typename F,
typename... T>
520 ->
decltype(std::declval<F>()(std::declval<T>()...))
524 return f(std::forward<T>(
arg)...);
Fixed-size array types for use on GPU and CPU.
Assertion macros used across AMReX for runtime consistency checks.
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
Container and helper utilities for sets of boxes on integer index space.
Integer-lattice boxes and helpers for defining index-space regions.
Helper for converting compiler-mangled type names to readable strings.
Maps FABs in a FabArray to MPI processes.
#define AMREX_NO_INLINE
Definition AMReX_Extension.H:141
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
void amrex_free(void *p)
Definition AMReX_Utility.cpp:933
void * amrex_malloc(std::size_t size)
Definition AMReX_Utility.cpp:927
Definition AMReX_Utility.H:169
bool TryFileOutput()
Definition AMReX_Utility.cpp:626
static void ClearStreamErrors()
Definition AMReX_Utility.H:176
bool TryOutput()
Definition AMReX_Utility.cpp:575
static int NStreamErrors()
Definition AMReX_Utility.H:175
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:50
Long size() const noexcept
Definition AMReX_Vector.H:54
Definition AMReX_Utility.H:157
friend std::istream & operator>>(std::istream &, const expect &exp)
const std::string & the_string() const
Definition AMReX_Utility.cpp:547
amrex_long Long
Definition AMReX_INT.H:30
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
Definition AMReX_Amr.cpp:50
std::ostream & ToString(std::ostream &os, const T &t, const char *symbol_begin="[", const char *symbol_delim=", ", const char *symbol_end="]", const char *symbol_str="\"", int limit=100)
Definition AMReX_Utility.H:461
void SyncStrings(const Vector< std::string > &localStrings, Vector< std::string > &syncedStrings, bool &alreadySynced)
Definition AMReX_Utility.cpp:674
double InvNormDistBest(double p)
This function returns an approximation of the inverse cumulative standard normal distribution functio...
Definition AMReX_Utility.cpp:387
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:116
int CRRBetweenLevels(int fromlevel, int tolevel, const Vector< int > &refratios)
Definition AMReX_Utility.cpp:232
void BroadcastStringArray(Vector< std::string > &bSA, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:896
__host__ __device__ T arg(const GpuComplex< T > &a_z) noexcept
Return the angle of a complex number's polar representation.
Definition AMReX_GpuComplex.H:403
Vector< std::string > UnSerializeStringArray(const Vector< char > &charArray)
Definition AMReX_Utility.cpp:850
std::conditional_t< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock > MaxResSteadyClock
Definition AMReX_Utility.H:217
amrex::Long bytesOf(const std::vector< T > &v)
Definition AMReX_Utility.H:352
bool FileExists(const std::string &filename)
Check if a file already exists. Return true if the filename is an existing file, directory,...
Definition AMReX_Utility.cpp:124
bool is_it(std::string const &s, T &v)
Useful C++ Utility Functions.
Definition AMReX_Utility.H:257
const std::vector< std::string > & Tokenize(const std::string &instr, const std::string &separators)
Splits "instr" into separate pieces based on "separators".
Definition AMReX_Utility.cpp:40
double second() noexcept
Definition AMReX_Utility.cpp:919
uint64_t hash_vector(const Vector< T > &vec, uint64_t seed=0xDEADBEEFDEADBEEF) noexcept
Definition AMReX_Utility.H:404
void UtilCreateCleanDirectory(const std::string &path, bool callbarrier=true)
Create a new directory, renaming the old one if it exists.
Definition AMReX_Utility.cpp:146
void CreateDirectoryFailed(const std::string &dir)
Output a message and abort when couldn't create the directory.
Definition AMReX_Utility.cpp:108
void BroadcastArray(Vector< T > &aT, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.H:269
bool UtilCreateDirectory(const std::string &path, mode_t mode, bool verbose=false)
Creates the specified directories. path may be either a full pathname or a relative pathname....
Definition AMReX_Utility.cpp:95
__host__ __device__ auto callNoinline(F const &f, T &&... arg) -> decltype(std::declval< F >()(std::declval< T >()...))
Call given function without inline.
Definition AMReX_Utility.H:519
void BroadcastString(std::string &bStr, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:880
__host__ __device__ GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
Complex expotential function.
Definition AMReX_GpuComplex.H:339
Vector< char > SerializeStringArray(const Vector< std::string > &stringArray)
Definition AMReX_Utility.cpp:836
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read a BoxND from is.
Definition AMReX_Box.H:1965
void hash_combine(uint64_t &seed, const T &val) noexcept
Definition AMReX_Utility.H:397
void Sleep(double sleepsec)
Definition AMReX_Utility.cpp:910
void UtilRenameDirectoryToOld(const std::string &path, bool callbarrier=true)
Rename a current directory if it exists.
Definition AMReX_Utility.cpp:201
double InvNormDist(double p)
This function returns an approximation of the inverse cumulative standard normal distribution functio...
Definition AMReX_Utility.cpp:266
void UtilCreateDirectoryDestructive(const std::string &path, bool callbarrier=true)
Create a new directory, removing old one if it exists.
Definition AMReX_Utility.cpp:175
std::string UniqueString()
Create a (probably) unique string.
Definition AMReX_Utility.cpp:130
void BroadcastBool(bool &bBool, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:865
void OutOfMemory()
Aborts after printing message indicating out-of-memory; i.e. operator new has failed....
Definition AMReX_Utility.cpp:226
Definition AMReX_TypeTraits.H:94