Skip to content

Commit

Permalink
try to clean up exceptions more neatly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Phil Tooley committed May 1, 2019
1 parent ee7c7c5 commit 38ab253
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 15 deletions.
59 changes: 48 additions & 11 deletions src/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

#include "exceptions.hpp"

#include <chrono>
#include <iostream>
#include <thread>

#include <mpi.h>

#include "gitstate.hpp"
#include "versioning.hpp"

constexpr std::string_view abort_info_pre = R"FATAL(!!! FATAL ERROR !!!:
Expand All @@ -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(){

Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions src/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/pfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ int main(int argc, char **argv)

void mainflow(std::shared_ptr<ConfigurationBase> config)
{
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

std::unique_ptr<Image> fixed;
try
{
Expand Down
11 changes: 7 additions & 4 deletions src/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void pfire_setup(const std::vector<std::string>& 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<char*> cstrings;
cstrings.resize(petsc_args.size());
Expand Down Expand Up @@ -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;
}
Expand All @@ -133,3 +134,5 @@ void print_welcome_message()

std::cout << welcomess.str();
}


60 changes: 60 additions & 0 deletions src/versioning.cpp
Original file line number Diff line number Diff line change
@@ -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 <petscsys.h>
#include <boost/version.hpp>

#ifdef USE_DCMTK
#include <dcmtk/config/osconfig.h>
#endif //USE_DCMTK

#ifdef USE_OIIO
#include <OpenImageIO/oiioversion.h>
#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
27 changes: 27 additions & 0 deletions src/versioning.hpp
Original file line number Diff line number Diff line change
@@ -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 <string>

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

0 comments on commit 38ab253

Please sign in to comment.