Skip to content

Commit

Permalink
Merge pull request #4680 from ye-luo/custom-isnan
Browse files Browse the repository at this point in the history
Fix error message printing issue in the safeguard exception catch
  • Loading branch information
prckent authored Jul 21, 2023
2 parents b85264d + 0bdde7a commit aea5dda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,23 @@ During Jastrow optimization, any update to the parameter data managed by the sha
the Jastrow objects. In another example, spline coefficients are managed by a shared pointer which achieves a single copy in
memory shared by an SPOSet and all of its clones.

Log and error output
~~~~~~~~~~~~~~~~~~~~

``app_log``, ``app_warning``, ``app_err`` and ``app_debug`` print out messages only on rank 0 to avoid repetitive messages from
every MPI rank. For this reason, they are only suitable for outputing messages identical to all MPI ranks. ``app_debug`` prints only
when ``--verbosity=debug`` command line option is used. Messages that come from only one or a few MPI ranks should use ``std::cout``
and ``std::cerr``.

If the code needs to be stopped after an unrecoverable error that happens uniformly on all the MPI ranks, a bad input for example,
avoid using ``app_err`` together with ``Communicate::abort(msg)`` or ``APP_ABORT(msg)`` because any MPI rank other than rank 0 may
stop the whole run before rank 0 is able to print out the error message. To secure the printout before stopping, use
``Communicate::barrier_and_abort(msg)`` if an MPI communicator is available or throw a custom exception ``UniformCommunicateError``
and capture it where ``Communicate::barrier_and_abort()`` can be used. Note that ``UniformCommunicateError`` can only be used for
uniform error, improper use may cause QMCPACK hanging.

In addition, avoid directly calling C function ``abort()``, ``exit()`` and ``MPI_Abort()`` for stopping the code.

.. include:: input_code.txt

.. _distance-tables:
Expand Down
5 changes: 2 additions & 3 deletions src/QMCApp/qmcapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ int main(int argc, char** argv)
}
catch (const std::exception& e)
{
app_error() << e.what() << std::endl;
std::cerr << e.what() << std::endl;
APP_ABORT("Unhandled Exception");
}
catch (...)
{
app_error() << "Exception not derived from std::exception thrown" << std::endl;
APP_ABORT("Unhandled Exception");
APP_ABORT("Unhandled Exception (not derived from std::exception)");
}

if (OHMMS::Controller->rank() == 0)
Expand Down

0 comments on commit aea5dda

Please sign in to comment.