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-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 * 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
50 runtimeErrorCollector = std::make_unique<RuntimeErrorCollector>(comm);
51}
52
54
56 const std::string &file,
57 const int line,
58 const std::string &function) {
59 return {*runtimeErrorCollector, level, file, line, function};
60}
61
63 runtimeErrorCollector->gather_local();
64}
65
67
72
73std::vector<RuntimeError> mpi_gather_runtime_errors_all(bool is_head_node) {
74 if (is_head_node) {
75 return runtimeErrorCollector->gather();
76 }
77 runtimeErrorCollector->gather_local();
78 return {};
79}
80} // namespace ErrorHandling
81
82void errexit() {
84
85 std::abort();
86}
87
89 using namespace ErrorHandling;
90 return runtimeErrorCollector->count(RuntimeError::ErrorLevel::ERROR);
91}
92
93int check_runtime_errors(boost::mpi::communicator const &comm) {
94 return boost::mpi::all_reduce(comm, check_runtime_errors_local(),
95 std::plus<int>());
96}
97
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.
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.
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.