3#include <AMReX_Config.H>
47 template <
typename T>
bool is_it (std::string
const& s, T& v);
50 const std::vector<std::string>&
Tokenize (
const std::string& instr,
51 const std::string& separators);
79 bool verbose =
false);
95 bool callbarrier =
true);
99 bool callbarrier =
true);
103 bool callbarrier =
true);
154 const Vector<int> &refratios);
163 explicit expect (std::string str_);
164 explicit expect (
const char* istr_);
166 [[nodiscard]]
const std::string&
the_string( )
const;
174 StreamRetry(std::ostream &os, std::string suffix,
int maxtries);
175 StreamRetry(std::string filename,
bool abortonretryfailure,
int maxtries);
183 bool abortOnRetryFailure =
true;
184 std::string fileName;
186 std::ostream::pos_type spos;
189 static int nStreamErrors;
194 void SyncStrings(
const Vector<std::string> &localStrings,
195 Vector<std::string> &syncedStrings,
bool &alreadySynced);
203 static const Long gcc_map_node_extra_bytes = 32L;
206 template <
typename Key,
typename T,
class Compare>
amrex::Long bytesOf (
const std::map<Key,T,Compare>& m);
213 template<
class T>
void BroadcastArray(Vector<T> &aT,
int myLocalId,
int rootId,
const MPI_Comm &localComm);
215 void Sleep (
double sleepsec);
219 std::chrono::high_resolution_clock,
220 std::chrono::steady_clock>;
221 double second () noexcept;
223 template<typename T>
void hash_combine (uint64_t & seed, const T & val) noexcept;
224 template<typename T> uint64_t
hash_vector (const
Vector<T> & vec, uint64_t seed = 0xDEADBEEFDEADBEEF) noexcept;
227 std::ostream&
ToString(std::ostream& os,
229 const
char* symbol_begin = "[",
230 const
char* symbol_delim = ", ",
231 const
char* symbol_end = "]",
232 const
char* symbol_str = "\"",
237 const
char* symbol_begin = "[",
238 const
char* symbol_delim = ", ",
239 const
char* symbol_end = "]",
240 const
char* symbol_str = "\"",
242 std::ostringstream ss = std::ostringstream{});
253 template <
typename F,
typename... T>
256 ->
decltype(std::declval<F>()(std::declval<T>()...));
262 std::istringstream ss(s);
265 std::getline(ss, left);
275 if(myLocalId == rootId) {
278 ParallelDescriptor::Bcast(&aT_Size, 1, rootId, localComm);
280 if(myLocalId != rootId) {
284 ParallelDescriptor::Bcast(aT.
dataPtr(), aT.
size(), rootId, localComm);
300#define BL_LANG_FORT 1
303#ifdef BL_FORT_USE_UNDERSCORE
304#undef BL_FORT_USE_UNDERSCORE
313#define BL_FORT_USE_UNDERSCORE 1
316#ifdef BL_FORT_USE_UPPERCASE
317#undef BL_FORT_USE_UPPERCASE
326#define BL_FORT_USE_UPPERCASE 1
329#ifdef BL_FORT_USE_LOWERCASE
330#undef BL_FORT_USE_LOWERCASE
339#define BL_FORT_USE_LOWERCASE 1
351#define BL_IGNORE_MAX 100000
357 return sizeof(v) + v.capacity()*
sizeof(T);
360template <
typename Key,
typename T,
class Compare>
364 return sizeof(m) + m.size()*(
sizeof(Key)+
sizeof(T)+gcc_map_node_extra_bytes);
402 seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed<<6) + (seed>>2);
409 for (
const auto &
x: vec) {
416namespace amrex::detail {
420 constexpr decltype((std::declval<T>().begin(), std::declval<T>().end(),
true)) HasBeginEnd() {
423 template <
class T,
class... Args>
424 constexpr bool HasBeginEnd(Args...) {
430 constexpr decltype((std::tuple_size<T>::value,
true)) HasTupleSize() {
433 template <
class T,
class... Args>
434 constexpr bool HasTupleSize(Args...) {
439 template <
class T, std::size_t... idx>
440 void ToStringTupleImp(std::index_sequence<idx...>, std::ostream& os,
const T& t,
441 const char* symbol_begin,
const char* symbol_delim,
442 const char* symbol_end,
const char* symbol_str,
int limit) {
445 auto op = [&](
auto& value) {
446 if (count > 0 && (count <= limit || limit < 0)) {
449 if (count < limit || limit < 0) {
450 ToString(os, value, symbol_begin, symbol_delim, symbol_end,
452 }
else if (count == limit) {
457 (op(std::get<idx>(t)), ...);
465 const char* symbol_delim,
const char* symbol_end,
466 const char* symbol_str,
int limit)
468 if constexpr (std::is_same_v<std::string, T> ||
469 std::is_same_v<std::string_view, T> ||
470 std::is_same_v<char*, std::decay_t<T>> ||
471 std::is_same_v<const char*, T>) {
473 os << symbol_str << t << symbol_str;
474 }
else if constexpr (std::is_same_v<signed char, T> ||
475 std::is_same_v<unsigned char, T>) {
477 os << static_cast<int>(t);
478 }
else if constexpr (std::is_pointer_v<T>) {
480 os << static_cast<const void*>(t);
481 }
else if constexpr (detail::HasBeginEnd<T>() || std::is_array_v<T>) {
485 for (
auto& value : t) {
489 if (count < limit || limit < 0) {
490 ToString(os, value, symbol_begin, symbol_delim, symbol_end,
492 }
else if (count == limit) {
499 }
else if constexpr (detail::HasTupleSize<T>()) {
501 detail::ToStringTupleImp(std::make_index_sequence<std::tuple_size_v<T>>{},
502 os, t, symbol_begin, symbol_delim, symbol_end,
512std::string
amrex::ToString(
const T& t,
const char* symbol_begin,
const char* symbol_delim,
513 const char* symbol_end,
const char* symbol_str,
514 int limit, std::ostringstream ss)
516 ToString(ss, t, symbol_begin, symbol_delim, symbol_end, symbol_str, limit);
520template <
typename F,
typename... T>
523 ->
decltype(std::declval<F>()(std::declval<T>()...))
527 return f(std::forward<T>(
arg)...);
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_NO_INLINE
Definition AMReX_Extension.H:136
#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:954
void * amrex_malloc(std::size_t size)
Definition AMReX_Utility.cpp:948
Definition AMReX_Utility.H:172
bool TryFileOutput()
Definition AMReX_Utility.cpp:647
static void ClearStreamErrors()
Definition AMReX_Utility.H:179
bool TryOutput()
Definition AMReX_Utility.cpp:596
static int NStreamErrors()
Definition AMReX_Utility.H:178
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:49
Long size() const noexcept
Definition AMReX_Vector.H:53
Definition AMReX_Utility.H:160
friend std::istream & operator>>(std::istream &, const expect &exp)
const std::string & the_string() const
Definition AMReX_Utility.cpp:568
amrex_long Long
Definition AMReX_INT.H:30
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
Definition AMReX_Amr.cpp:49
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:464
void SyncStrings(const Vector< std::string > &localStrings, Vector< std::string > &syncedStrings, bool &alreadySynced)
Definition AMReX_Utility.cpp:695
double InvNormDistBest(double p)
This function returns an approximation of the inverse cumulative standard normal distribution functio...
Definition AMReX_Utility.cpp:408
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:137
bool is_integer(const char *str)
Useful C++ Utility Functions.
Definition AMReX_Utility.cpp:35
int CRRBetweenLevels(int fromlevel, int tolevel, const Vector< int > &refratios)
Definition AMReX_Utility.cpp:253
void BroadcastStringArray(Vector< std::string > &bSA, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:917
__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:871
std::conditional_t< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock > MaxResSteadyClock
Definition AMReX_Utility.H:220
amrex::Long bytesOf(const std::vector< T > &v)
Definition AMReX_Utility.H:355
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:145
bool is_it(std::string const &s, T &v)
Return true and store value in v if string s is type T.
Definition AMReX_Utility.H:260
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:61
double second() noexcept
Definition AMReX_Utility.cpp:940
uint64_t hash_vector(const Vector< T > &vec, uint64_t seed=0xDEADBEEFDEADBEEF) noexcept
Definition AMReX_Utility.H:407
void UtilCreateCleanDirectory(const std::string &path, bool callbarrier=true)
Create a new directory, renaming the old one if it exists.
Definition AMReX_Utility.cpp:167
void CreateDirectoryFailed(const std::string &dir)
Output a message and abort when couldn't create the directory.
Definition AMReX_Utility.cpp:129
void BroadcastArray(Vector< T > &aT, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.H:272
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:116
__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:522
void BroadcastString(std::string &bStr, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:901
__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:857
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read from istream.
Definition AMReX_Box.H:1825
void hash_combine(uint64_t &seed, const T &val) noexcept
Definition AMReX_Utility.H:400
void Sleep(double sleepsec)
Definition AMReX_Utility.cpp:931
void UtilRenameDirectoryToOld(const std::string &path, bool callbarrier=true)
Rename a current directory if it exists.
Definition AMReX_Utility.cpp:222
double InvNormDist(double p)
This function returns an approximation of the inverse cumulative standard normal distribution functio...
Definition AMReX_Utility.cpp:287
void UtilCreateDirectoryDestructive(const std::string &path, bool callbarrier=true)
Create a new directory, removing old one if it exists.
Definition AMReX_Utility.cpp:196
std::string UniqueString()
Create a (probably) unique string.
Definition AMReX_Utility.cpp:151
void BroadcastBool(bool &bBool, int myLocalId, int rootId, const MPI_Comm &localComm)
Definition AMReX_Utility.cpp:886
void OutOfMemory()
Aborts after printing message indicating out-of-memory; i.e. operator new has failed....
Definition AMReX_Utility.cpp:247
Definition AMReX_TypeTraits.H:99