Skip to content

Commit

Permalink
UniqueString tweak
Browse files Browse the repository at this point in the history
Previously UniqueString used MPI_Wtime, which could have a very low
resolution (1e-5s) on some machines. In this PR, we switch to use
amrex::second(), which uses the highest resolution steady clock (usually
1.e-9s). We have also changed a hardwired number according to resolution of
the clock so that the digits are not wasted on trailing zeros.
  • Loading branch information
WeiqunZhang committed Aug 28, 2023
1 parent c45770c commit 60498f2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Src/Base/AMReX_Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,17 @@ amrex::FileExists(const std::string &filename)
std::string
amrex::UniqueString()
{
std::stringstream tempstring;
tempstring << std::setprecision(11) << std::fixed << ParallelDescriptor::second();
auto const tsl = tempstring.str().length();
return(tempstring.str().substr(tsl/2, tsl));
constexpr int len = 7;
static const auto n = std::max
(len,
static_cast<int>(
std::round(std::log10(double(MaxResSteadyClock::period::den)
/double(MaxResSteadyClock::period::num)))));
std::stringstream tempstring;
tempstring << std::setprecision(n) << std::fixed << amrex::second()+100.0;
auto const ts = tempstring.str();
auto const tsl = ts.length();
return ts.substr(tsl-len,tsl); // tsl-len >= 0 becaues n >= len
}

void
Expand Down

0 comments on commit 60498f2

Please sign in to comment.