ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
errorhandling.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21/** \file
22 * This file contains the errorhandling code for severe errors, like
23 * a broken bond or illegal parameter combinations.
24 */
25
26#ifndef ESPRESSO_SRC_CORE_ERROR_HANDLING_HPP
27#define ESPRESSO_SRC_CORE_ERROR_HANDLING_HPP
28
29#include "config/config.hpp"
30
33
34#include <memory>
35#include <string>
36#include <vector>
37
38/* Forward declaration of MpiCallbacks,
39 * so we don't have to include the header.
40 * It depends on mpi and cannot be in cuda
41 * code.
42 */
43namespace Communication {
44class MpiCallbacks;
45}
46
47namespace boost {
48namespace mpi {
49class communicator;
50}
51} // namespace boost
52
53/**
54 * @brief exit ungracefully,
55 * core dump if switched on.
56 */
57[[noreturn]] void errexit();
58
59/**
60 * @brief Count runtime errors on all nodes.
61 * This has to be called on all nodes synchronously.
62 *
63 * @return the number of error messages of all nodes together.
64 */
65int check_runtime_errors(boost::mpi::communicator const &comm);
66
67/**
68 * @brief Count runtime errors on the local node.
69 * This has to be called on all nodes synchronously.
70 *
71 * @return the number of error messages on this node.
72 */
74
75/**
76 * @brief Flush runtime errors to standard error on the local node.
77 * This is used to clear pending runtime error messages when the
78 * call site is handling an exception that needs to be re-thrown
79 * instead of being queued as an additional runtime error message.
80 */
82
83namespace ErrorHandling {
84/**
85 * @brief Initialize the error collection system.
86 *
87 * @param callbacks Callbacks system the error handler should be on.
88 */
89void init_error_handling(std::weak_ptr<Communication::MpiCallbacks> callbacks);
90
91RuntimeErrorStream _runtimeMessageStream(RuntimeError::ErrorLevel level,
92 const std::string &file, int line,
93 const std::string &function);
94
95#define runtimeErrorMsg() \
96 ErrorHandling::_runtimeMessageStream( \
97 ErrorHandling::RuntimeError::ErrorLevel::ERROR, __FILE__, __LINE__, \
98 ESPRESSO_PRETTY_FUNCTION_EXTENSION)
99
100#define runtimeWarningMsg() \
101 ErrorHandling::_runtimeMessageStream( \
102 ErrorHandling::RuntimeError::ErrorLevel::WARNING, __FILE__, __LINE__, \
103 ESPRESSO_PRETTY_FUNCTION_EXTENSION)
104
105/** @brief Gather messages on main rank. Only call from main rank. */
106std::vector<RuntimeError> mpi_gather_runtime_errors();
107/** @brief Gather messages on main rank. Call on all ranks. */
108std::vector<RuntimeError> mpi_gather_runtime_errors_all(bool is_head_node);
109
110} // namespace ErrorHandling
111
112#endif
Communicator communicator
This file contains the defaults for ESPResSo.
int check_runtime_errors(boost::mpi::communicator const &comm)
Count runtime errors on all nodes.
void flush_runtime_errors_local()
Flush runtime errors to standard error on the local node.
int check_runtime_errors_local()
Count runtime errors on the local node.
void errexit()
exit ungracefully, core dump if switched on.
RuntimeErrorStream _runtimeMessageStream(RuntimeError::ErrorLevel level, const std::string &file, const int line, const std::string &function)
std::vector< RuntimeError > mpi_gather_runtime_errors()
Gather messages on main rank.
std::vector< RuntimeError > mpi_gather_runtime_errors_all(bool is_head_node)
Gather messages on main rank.
void init_error_handling(std::weak_ptr< Communication::MpiCallbacks > callbacks)
Initialize the error collection system.
ErrorLevel
The error level, warnings are only displayed to the user, errors are fatal.