diff --git a/docs/developing.rst b/docs/developing.rst index 5a26518d87..ba6abd0507 100644 --- a/docs/developing.rst +++ b/docs/developing.rst @@ -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: diff --git a/src/QMCApp/qmcapp.cpp b/src/QMCApp/qmcapp.cpp index 1d35ea486c..29356f8086 100644 --- a/src/QMCApp/qmcapp.cpp +++ b/src/QMCApp/qmcapp.cpp @@ -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)