ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
errorhandling.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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 * Implementation of \ref errorhandling.hpp.
23 */
24
25#include "errorhandling.hpp"
26#include "communication.hpp"
27
28#include "MpiCallbacks.hpp"
30
31#include <boost/mpi/collectives.hpp>
32#include <boost/mpi/communicator.hpp>
33
34#include <cstdlib>
35#include <functional>
36#include <memory>
37#include <string>
38#include <utility>
39#include <vector>
40
41namespace ErrorHandling {
42/** RuntimeErrorCollector instance.
43 * This is a unique pointer so we don't
44 * leak on repeated calls of @ref init_error_handling.
45 */
46static std::unique_ptr<RuntimeErrorCollector> runtimeErrorCollector;
47
48void init_error_handling(boost::mpi::communicator const &comm) {
49 runtimeErrorCollector = std::make_unique<RuntimeErrorCollector>(comm);
50}
51
53
55 const std::string &file,
56 const int line,
57 const std::string &function) {
58 return {*runtimeErrorCollector, level, file, line, function};
59}
60
62 runtimeErrorCollector->gather_local();
63}
64
66
71
72std::vector<RuntimeError> mpi_gather_runtime_errors_all(bool is_head_node) {
73 if (is_head_node) {
74 return runtimeErrorCollector->gather();
75 }
76 runtimeErrorCollector->gather_local();
77 return {};
78}
79
81 bool has_any_message =
82 runtimeErrorCollector->count_local(
84 boost::mpi::reduce(runtimeErrorCollector->comm(), has_any_message,
85 std::logical_or<bool>(), 0);
86}
87
89
102} // namespace ErrorHandling
103
104void errexit() {
106
107 std::abort();
108}
109
111 using namespace ErrorHandling;
112 return runtimeErrorCollector->count_local(RuntimeError::ErrorLevel::ERROR);
113}
114
115int check_runtime_errors(boost::mpi::communicator const &comm) {
116 return boost::mpi::all_reduce(comm, check_runtime_errors_local(),
117 std::plus<int>());
118}
119
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
#define REGISTER_CALLBACK(cb)
Register a static callback without return value.
Create a runtime error message via the streaming operator.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
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.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
MpiCallbacks & mpiCallbacks()
Returns a reference to the global callback class instance.
static void mpi_poll_runtime_messages_local()
bool mpi_poll_runtime_messages()
Check whether there is at least 1 flying runtime messages on any node.
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.
static std::unique_ptr< RuntimeErrorCollector > runtimeErrorCollector
RuntimeErrorCollector instance.
static void mpi_gather_runtime_errors_local()
void init_error_handling(boost::mpi::communicator const &comm)
Initialize the error collection system.
void deinit_error_handling()
STL namespace.