How do you stop in TotalView after an MPI Error?
I am using开发者_如何学运维 TotalView and am getting an MPI_Error. However, Totalview does not stop on this error and I can't find where it is occurring. I believe this also applies to GDB.
Define an MPI_ErrHandler. It gets called in place of the default MPI handler and you can set a breakpoint there. Suggestions welcome on how to get it to print the same thing as the MPI error, or better yet, more information.
MPIErrorHander.hpp:
#define MPIERRORHANDLER_HPP
#ifdef mpi
#include <stdexcept>
#include <string>
#include <mpi.h>
namespace MPIErrorHandler {
//subclass so we can specifically catch MPI errors
class Exception : public std::exception {
public:
Exception(std::string const& what) : std::exception(), m_what(what) { }
virtual ~Exception() throw() { }
virtual const char* what() const throw() {
return m_what.c_str( );
}
protected:
std::string m_what;
};
void convertToException( MPI_Comm *comm, int *err, ... );
}
#endif // mpi
#endif // MPIERRORHANDLER_HPP
MPIErrorHandler.cpp:
#ifdef mpi
#include "MPIErrorHandler.hpp"
void MPIErrorHandler::convertToException( MPI_Comm *comm, int *err, ... ) {
throw Exception(std::string("MPI Error."));
}
#endif //mpi
main.cpp:
#include "MPIErrorHandler.hpp"
{
MPI_Errhandler mpiErrorHandler;
MPI_Init( &argc, &argv );
//Set this up so we always get an exception that will stop TV
MPI_Errhandler_create( MPIErrorHandler::convertToException,
&mpiErrorHandler );
MPI_Errhandler_set( MPI_COMM_WORLD, mpiErrorHandler );
// Your program here.
MPI_Finalize( );
}
精彩评论