From 38ab253ad73daf5bc6de67b47c80f33d98ed32b3 Mon Sep 17 00:00:00 2001 From: Phil Tooley Date: Wed, 1 May 2019 15:46:00 +0100 Subject: [PATCH] try to clean up exceptions more neatly Slightly hackish approach to try to not get mangled error messages by temporaly separating threads in the error handler. Only works if they arrive with less than 200ms spacing, but that should cover most cases for patterns within pFIRE --- src/exceptions.cpp | 59 ++++++++++++++++++++++++++++++++++++--------- src/exceptions.hpp | 1 + src/pfire.cpp | 3 +++ src/setup.cpp | 11 +++++---- src/versioning.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/versioning.hpp | 27 +++++++++++++++++++++ 6 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 src/versioning.cpp create mode 100644 src/versioning.hpp diff --git a/src/exceptions.cpp b/src/exceptions.cpp index a91c28d..2813687 100644 --- a/src/exceptions.cpp +++ b/src/exceptions.cpp @@ -15,11 +15,14 @@ #include "exceptions.hpp" +#include #include +#include #include #include "gitstate.hpp" +#include "versioning.hpp" constexpr std::string_view abort_info_pre = R"FATAL(!!! FATAL ERROR !!!: @@ -32,19 +35,38 @@ Help is available through the pFIRE issue tracker on github, but first please en 2. Your input files are not corrupt 3. If you are running on HPC please check there are no hardware issues -If you have checked the above and the bug still happens: https://github.com/INSIGNEO/pFIRE/issues +If you have checked the above and the bug still occurs please report it via +https://github.com/INSIGNEO/pFIRE/issues Your report should include: - Input configuration file -- Details of the images being registered -- The exact pFIRE version: )FATAL"; +- Details of the images being registered (format, dimensions) +- Basic hardware details, operating system and version +- The exact pFIRE version: -constexpr std::string_view abort_info_post = R"FATAL( + - )FATAL"; + +constexpr std::string_view abort_info_libheader = R"FATAL( +- The library versions in use: )FATAL"; +constexpr std::string_view abort_info_petsc = " - Petsc Version: "; +constexpr std::string_view abort_info_boost = " - Boost Version: "; + +#ifdef USE_OIIO +constexpr std::string_view abort_info_oiio = " - OpenImageIO Version: "; +#endif + +#ifdef USE_DCMTK +constexpr std::string_view abort_info_dcmtk = " - DCMTK Version: "; +#endif //USE_DCMTK + +constexpr std::string_view abort_info_post = R"FATAL( +)FATAL"; + void abort_with_unhandled_error(){ @@ -53,6 +75,10 @@ void abort_with_unhandled_error(){ std::exception_ptr eptr = std::current_exception(); + // Try to separate threads that arrive here together + // to avoid garbling stdout too much + std::this_thread::sleep_for(std::chrono::milliseconds(200*rank)); + try { if (eptr) { @@ -65,11 +91,7 @@ void abort_with_unhandled_error(){ << e.what() << "\n\"\"\"\n"; } - if(rank == 0){ - std::cout << abort_info_pre - << git_version_string() - << abort_info_post; - } + print_abort_message(); MPI_Abort(MPI_COMM_WORLD, -1); @@ -80,9 +102,24 @@ void sigterm_handler(int signal){ int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if(rank == 0){ + std::cout << "Rank " << rank << " received signal " << signal; + + std::this_thread::sleep_for(std::chrono::milliseconds(50*rank)); + print_abort_message(); +} + +void print_abort_message(){ + std::cout << abort_info_pre << git_version_string() + << abort_info_libheader + << abort_info_petsc << get_version_string_petsc() << "\n" + << abort_info_boost << get_version_string_boost() << "\n" +#ifdef USE_OIIO + << abort_info_oiio << get_version_string_oiio() << "\n" +#endif //USE_OIIO +#ifdef USE_DCMTK + << abort_info_dcmtk << get_version_string_dcmtk() << "\n" +#endif //USE_DCMTK << abort_info_post; - } } diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 5bb1bee..541b792 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -22,6 +22,7 @@ void abort_with_unhandled_error(); void sigterm_handler(int signal); +void print_abort_message(); class pFIREBaseError: public std::runtime_error { public: diff --git a/src/pfire.cpp b/src/pfire.cpp index 8d71bc9..dc2bb25 100644 --- a/src/pfire.cpp +++ b/src/pfire.cpp @@ -87,6 +87,9 @@ int main(int argc, char **argv) void mainflow(std::shared_ptr config) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + std::unique_ptr fixed; try { diff --git a/src/setup.cpp b/src/setup.cpp index ce02947..52d6ea8 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -66,6 +66,7 @@ void pfire_setup(const std::vector& petsc_args, bool silent) // Setup terminate handler std::set_terminate(abort_with_unhandled_error); std::signal(SIGTERM, sigterm_handler); + std::signal(SIGABRT, sigterm_handler); std::vector cstrings; cstrings.resize(petsc_args.size()); @@ -104,11 +105,11 @@ void check_comm_size_and_warn_odd() if (comm_size > 2 && comm_size % 2 == 1) { - std::cout << "!!!! WARNING !!!!\n" - << "Using an odd number of processors is not recommended.\n" - << "This makes efficient subdivision of the problem much harder and will likely " + std::cout << "\n!!!! WARNING !!!!\n" + << "\tUsing an odd number of processors is not recommended.\n" + << "\tThis makes efficient subdivision of the problem much harder and will likely " << "lead to reduced performance.\n" - << "Extreme cases may make viable partitioning impossible and cause job failure. " + << "\tExtreme cases may make viable partitioning impossible and cause job failure. " << "You have been warned!\n\n" << std::flush; } @@ -133,3 +134,5 @@ void print_welcome_message() std::cout << welcomess.str(); } + + diff --git a/src/versioning.cpp b/src/versioning.cpp new file mode 100644 index 0000000..f0af6d4 --- /dev/null +++ b/src/versioning.cpp @@ -0,0 +1,60 @@ +// +// Copyright 2019 University of Sheffield +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#ifdef USE_DCMTK +#include +#endif //USE_DCMTK + +#ifdef USE_OIIO +#include +#endif //USE_OIIO + +#include "types.hpp" + +std::string get_version_string_petsc() +{ + integer major, minor, subminor; + PetscGetVersionNumber(&major, &minor, &subminor, nullptr); + + return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(subminor); +} + +std::string get_version_string_boost() +{ + // See "Boost Informational Macros" section of boost::config docs + integer major = BOOST_VERSION / 100000; + integer minor = (BOOST_VERSION / 100) % 1000; + integer subminor = BOOST_VERSION % 100; + + return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(subminor); +} + +#ifdef USE_DCMTK +std::string get_version_string_dcmtk() +{ + return std::string(PACKAGE_VERSION); +} +#endif //USE_DCMTK + +#ifdef USE_OIIO +std::string get_version_string_oiio() +{ + return std::to_string(OIIO_VERSION_MAJOR) + "." + std::to_string(OIIO_VERSION_MINOR) + "." + + std::to_string(OIIO_VERSION_PATCH); +} +#endif //USE_OIIO diff --git a/src/versioning.hpp b/src/versioning.hpp new file mode 100644 index 0000000..14482ea --- /dev/null +++ b/src/versioning.hpp @@ -0,0 +1,27 @@ +// +// Copyright 2019 University of Sheffield +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +std::string get_version_string_petsc(); +std::string get_version_string_boost(); + +#ifdef USE_DCMTK +std::string get_version_string_dcmtk(); +#endif //USE_DCMTK + +#ifdef USE_OIIO +std::string get_version_string_oiio(); +#endif //USE_OIIO