Skip to content

Commit

Permalink
IParser: Use long long int
Browse files Browse the repository at this point in the history
* Use long long int as the underlying integer data type in IParser.

* Extend number format to include `3e9`, `2.34e6`, `1'000'000`, etc.
  • Loading branch information
WeiqunZhang committed Jul 24, 2024
1 parent 930e75e commit 4e9fcda
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 187 deletions.
6 changes: 5 additions & 1 deletion Docs/sphinx_documentation/source/Basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ Besides :cpp:`amrex::Parser` for floating point numbers, AMReX also provides
similarity, but floating point number specific functions (e.g., ``sqrt``,
``sin``, etc.) are not supported in ``IParser``. In addition to ``/`` whose
result truncates towards zero, the integer parser also supports ``//`` whose
result truncates towards negative infinity.
result truncates towards negative infinity. Single quotes ``'`` are allowed
as a separator for :cpp:`IParser` numbers just like C++ integer
literals. Additionally, a floating point like number with a positive
exponent may be accepted as an integer if it is reasonable to do so. For
example, it's okay to have ``1.234e3``, but ``1.23e2`` is an error.

.. _sec:basics:initialize:

Expand Down
11 changes: 6 additions & 5 deletions Src/Base/Parser/AMReX_IParser.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ struct IParserExecutor
{
template <int M=N, std::enable_if_t<M==0,int> = 0>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int operator() () const noexcept
long long operator() () const noexcept
{
AMREX_IF_ON_DEVICE((return iparser_exe_eval(m_device_executor, nullptr);))
AMREX_IF_ON_HOST((return iparser_exe_eval(m_host_executor, nullptr);))
}

template <typename... Ts>
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
std::enable_if_t<sizeof...(Ts) == N, int>
std::enable_if_t<sizeof...(Ts) == N && std::conjunction_v<std::is_integral<Ts>...>,
long long>
operator() (Ts... var) const noexcept
{
amrex::GpuArray<int,N> l_var{var...};
amrex::GpuArray<long long,N> l_var{var...};
AMREX_IF_ON_DEVICE((return iparser_exe_eval(m_device_executor, l_var.data());))
AMREX_IF_ON_HOST((return iparser_exe_eval(m_host_executor, l_var.data());))
}

[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int operator() (GpuArray<int,N> const& var) const noexcept
long long operator() (GpuArray<long long, N> const& var) const noexcept
{
AMREX_IF_ON_DEVICE((return iparser_exe_eval(m_device_executor, var.data());))
AMREX_IF_ON_HOST((return iparser_exe_eval(m_host_executor, var.data());))
Expand All @@ -62,7 +63,7 @@ public:

explicit operator bool () const;

void setConstant (std::string const& name, int c);
void setConstant (std::string const& name, long long c);

void registerVariables (Vector<std::string> const& vars);

Expand Down
2 changes: 1 addition & 1 deletion Src/Base/Parser/AMReX_IParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ IParser::operator bool () const
}

void
IParser::setConstant (std::string const& name, int c)
IParser::setConstant (std::string const& name, long long c)
{
if (m_data && m_data->m_iparser) {
iparser_setconst(m_data->m_iparser, name.c_str(), c);
Expand Down
Loading

0 comments on commit 4e9fcda

Please sign in to comment.