21 #include <stk_util/diag/Env.hpp> 22 #include <stk_util/diag/Platform.hpp> 24 #include <stk_util/parallel/ExceptionReport.hpp> 27 #include <stk_util/diag/Trace.hpp> 38 ParallelThrowRegistry &
43 return s_parallelThrowRegistry;
47 ParallelThrowRegistry::Registry::Registry()
51 ParallelThrowRegistry::Registry::~Registry()
56 for (iterator it = begin(); it != end(); ++it, ++it)
62 ParallelThrowRegistry::register_exception_a(
63 const std::type_info & exception_type,
64 ExParallel * exception)
67 m_registry.push_back(Registry::value_type(&exception_type, exception));
68 mpih::Add_Handle(*exception);
75 const std::type_info & exception_type)
77 for (Registry::iterator it = m_registry.begin(); it != m_registry.end(); ++it)
78 if (*(*it).first == exception_type)
92 const std::exception & x,
93 const std::string & append_message)
100 *exception << x.
what() << append_message;
110 x <<
"Unknown exception";
121 if (!registered_exception)
131 mpih::Set_Local_Handle(const_cast<ExParallel &>(*registered_exception));
141 if (!registered_exception)
151 mpih::Set_Local_Handle(const_cast<ExParallel &>(*registered_exception));
164 LogicError::registerException();
165 DomainError::registerException();
166 InvalidArgument::registerException();
167 LengthError::registerException();
168 OutOfRange::registerException();
169 RuntimeError::registerException();
170 RangeError::registerException();
171 OverflowError::registerException();
172 UnderflowError::registerException();
175 mpih::Activate_Handles();
184 MPI_Comm_size(mpi_comm, &nprocs);
188 mpih::Get_Global_Handles(handles);
190 MPIH_Handler_compete handler_compete_fn;
191 MPIH_Handler_execute handler_execute_fn;
192 mpih::Get_Functions(&handler_compete_fn ,
193 &handler_execute_fn);
200 mpih::Reset_Local_Handle();
212 for (
int i = 0; i < nprocs; ++i) {
226 int originating_processor = -1;
228 for (
int i = 0; i < nprocs; ++i) {
232 if (handler_compete_fn)
233 (handler_compete_fn) (reinterpret_cast<void **>(&handles[i]), the_exception);
234 if ( handles[i] != the_exception ) {
236 originating_processor = i;
257 int description_len = description.length();
258 MPI_Bcast(&description_len,
261 originating_processor,
264 char *description_buf =
new char[description_len];
265 description.copy(description_buf, description_len);
267 MPI_Bcast(description_buf,
270 originating_processor,
274 const std::string &traceback(the_exception->
getTraceback());
275 int traceback_len = traceback.length();
276 MPI_Bcast(&traceback_len,
279 originating_processor,
282 char *traceback_buf =
new char[traceback_len];
283 traceback.copy(traceback_buf, traceback_len);
285 MPI_Bcast(traceback_buf,
288 originating_processor,
292 the_exception->
setDescription(std::string(description_buf, description_len));
293 the_exception->
setTraceback(std::string(traceback_buf, traceback_len));
300 #ifdef SIERRA_MPIH_VERBOSE 302 <<
"*************** Exception handling ***************"<<endl
303 <<
" A parallel exception of type "<<
typeid(*the_exception).name()<<endl
304 <<
" will be thrown on all processors."<<endl;
307 delete [] traceback_buf;
308 delete [] description_buf;
312 #ifdef SIERRA_MPIH_VERBOSE 314 <<
"*************** Exception handling ***************"<<endl
315 <<
" A parallel exception of type Unknown_Exception"<<endl
316 <<
" will be thrown on all processors."<<endl;
ExParallel & clear()
Member function clear clears the contents of the exception.
void sierra_exception_throw()
Member function sierra_exception_throw is called whenever a parallel exception is constructed...
void parallel_throw(MPI_Comm mpi_comm)
Function parallel_throw throws a consistant exception in parallel. parallel_throw is called after the...
std::ostream & outputP0()
Function outputP0 returns the processor output log stream on processor 0 and the null log stream on a...
void throw_copy(const std::exception &x, const std::string &append_message)
Function throw_copy throws a copy of the exception. The exception is located in the parallel exceptio...
virtual const char * what() const
Member function what returns the exception's description.
std::ostringstream & getDescriptionStream()
Member function getDescriptionStream returns the stream used to assemble the description.
ExParallel * findException(const std::type_info &exception_type)
Member function findException returns a pointer to the matching exception in parallel exception regis...
std::string getDescription() const
Member function getDescription returns the exception's description.
Template ExTemp takes a zero argument exception and makes it into a parallel throwable and put-to-abl...
ExParallel & setTraceback(const std::string &traceback)
Member function setTraceback sets the exception's traceback to the caller generating the exception...
static std::string printTraceback(const TracebackStack &traceback_stack)
Member function printTraceback writes the traceback stack function specifications to the output strea...
void set_exception()
Function set_exception is called on a single processor when an exception is caught. The next collective communication will propogate the exception to all processors. This flavor is called when an unknown exception (...) is caught.
static ParallelThrowRegistry & instance()
Member function instance returns the singleton instance for the parallel exception registry...
Class ParallelThrowRegistry is a registry of known parallel exceptions. For the negotiation of parall...
ExParallel & setParallel(int parallel)
Member function setParallel sets the originating processor for an exception that is being thrown in p...
virtual void parallel_handler()
Member function parallel_handler is called just before a parallel exception is thrown. It is guaranteed to be called in parallel on all processors, so collective communication is allowed inside Parallel_Handler. This function might be used to copy information to all processors. The default is to do nothing.
static void registerException()
Member function registerException registers the exception with the parallel exception registry...
void register_stl_parallel_exceptions()
Member function register_stl_parallel_exceptions registers the stl exceptions with the parallel excep...
virtual void throw_copy() const =0
Member function throw_copy is a pure virtual function which is allows the copying and throwing of the...
const std::string & getTraceback() const
Member function getTraceback returns the exception's traceback string.
Class ExParallel implements the features of a parallel exception. It is a std::string which stores th...
ExTemp< std::exception > Exception
Defined in
ExParallel & setDescription(const std::string &description)
Member function setDescription sets the value of the exception's description.