How do you stop in TotalView after an MPI Error?

天涯浪子 提交于 2019-12-25 08:48:23

问题


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.


回答1:


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( ); 
}


来源:https://stackoverflow.com/questions/2885117/how-do-you-stop-in-totalview-after-an-mpi-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!