1 ////////////////////////////////////////////////////////////////////////////////////// 2 // This file is distributed under the University of Illinois/NCSA Open Source License. 3 // See LICENSE file in top directory for details. 4 // 5 // Copyright (c) 2020 QMCPACK developers. 6 // 7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab 8 // 9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab 10 ////////////////////////////////////////////////////////////////////////////////////// 11 #ifndef QMCPLUSPLUS_UNIFORMCOMMUNICATEERROR_H 12 #define QMCPLUSPLUS_UNIFORMCOMMUNICATEERROR_H 13 #include <exception> 14 namespace qmcplusplus 15 { 16 /** This a subclass for runtime errors that will occur on all ranks. 17 * 18 * This is intended to be thrown and caught within a single Communicate context. 19 * 20 * Intended use is with a catch block like this: 21 * 22 * catch (const UniformMPIerror& ue) 23 * { 24 * my_local_comm->barrier_and_abort(ue.what()); 25 * } 26 * 27 * Which insures that the error message actually makes it out on the head 28 * rank before the MPI processes are aborted. 29 * 30 * If even one member of the comm i.e. my_local_comm does not experience the issue 31 * you will HANG the job until the walltime expires. When in doubt it is better 32 * to lose the error message until the crash is examined in a debugger. 33 * 34 * Because of this you should catch the exception as soon as you have access to a Communicate 35 * instance. However unlike the unit test hostile `comm->barrier_and_abort` you can and 36 * should check that an exception is emitted so don't catch it in the same method/function. 37 */ 38 class UniformCommunicateError : public std::runtime_error 39 { 40 public: UniformCommunicateError(const std::string & what_arg)41 UniformCommunicateError(const std::string& what_arg) : std::runtime_error(what_arg) {} UniformCommunicateError(const char * what_arg)42 UniformCommunicateError(const char* what_arg) : std::runtime_error(what_arg) {} 43 }; 44 45 } // namespace qmcplusplus 46 47 #endif 48