0

我正在使用 TotalView 并收到 MPI_Error。但是,Totalview 不会因为这个错误而停止,我找不到它发生的位置。我相信这也适用于 GDB。

4

1 回答 1

0

定义一个 MPI_ErrHandler。它被调用来代替默认的 MPI 处理程序,您可以在那里设置断点。欢迎提出关于如何让它打印与 MPI 错误相同的内容的建议,或者更好的更多信息。

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

主.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( ); 
}
于 2010-05-21T19:54:28.063 回答