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#pragma once
27
28#include <config/config.hpp>
29
32
33#include <memory>
34#include <string>
35#include <vector>
36
37/* Forward declaration of boost::mpi::communicator,
38 * so we don't have to include the header.
39 * It depends on mpi and cannot be in cuda
40 * code.
41 */
42namespace boost {
43namespace mpi {
44class communicator;
45}
46} // namespace boost
47
48/**
49 * @brief exit ungracefully,
50 * core dump if switched on.
51 */
52[[noreturn]] void errexit();
53
54/**
55 * @brief Count runtime errors on all nodes.
56 * This has to be called on all nodes synchronously.
57 *
58 * @return the number of error messages of all nodes together.
59 */
60int check_runtime_errors(boost::mpi::communicator const &comm);
61
62/**
63 * @brief Count runtime errors on the local node.
64 * This has to be called on all nodes synchronously.
65 *
66 * @return the number of error messages on this node.
67 */
69
70/**
71 * @brief Flush runtime errors to standard error on the local node.
72 * This is used to clear pending runtime error messages when the
73 * call site is handling an exception that needs to be re-thrown
74 * instead of being queued as an additional runtime error message.
75 */
77
78namespace ErrorHandling {
79/**
80 * @brief Initialize the error collection system.
81 */
82void init_error_handling(boost::mpi::communicator const &comm);
84
85RuntimeErrorStream _runtimeMessageStream(RuntimeError::ErrorLevel level,
86 const std::string &file, int line,
87 const std::string &function);
88
89#define runtimeErrorMsg() \
90 ErrorHandling::_runtimeMessageStream( \
91 ErrorHandling::RuntimeError::ErrorLevel::ERROR, __FILE__, __LINE__, \
92 ESPRESSO_PRETTY_FUNCTION_EXTENSION)
93
94#define runtimeWarningMsg() \
95 ErrorHandling::_runtimeMessageStream( \
96 ErrorHandling::RuntimeError::ErrorLevel::WARNING, __FILE__, __LINE__, \
97 ESPRESSO_PRETTY_FUNCTION_EXTENSION)
98
99/** @brief Gather messages on main rank. Only call from main rank. */
100std::vector<RuntimeError> mpi_gather_runtime_errors();
101/** @brief Gather messages on main rank. Call on all ranks. */
102std::vector<RuntimeError> mpi_gather_runtime_errors_all(bool is_head_node);
103
104} // namespace ErrorHandling
Communicator communicator
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(boost::mpi::communicator const &comm)
Initialize the error collection system.
void deinit_error_handling()