【问题标题】:How do you stop in TotalView after an MPI Error?在 MPI 错误后如何在 TotalView 中停止?
【发布时间】:2010-05-21 19:49:40
【问题描述】:

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

【问题讨论】:

    标签: c++ mpi totalview


    【解决方案1】:

    定义一个 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
    

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

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2019-03-23
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      相关资源
      最近更新 更多