Program Listing for File mpi_exception.hpp

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/intel-qs/checkouts/docs/include/mpi_exception.hpp)

#ifndef IQS_MPI_EXCEPTION_HPP
#define IQS_MPI_EXCEPTION_HPP



#include <exception>
#include <string>
#include <unistd.h>


namespace qhipster {

namespace mpi {


class Exception : public std::exception
{
 public:

  Exception(const char* routine, int error_code);

  virtual ~Exception() throw();

  virtual const char* what() const throw() { return this->description_.c_str(); }

  const char* routine() const { return routine_; }

  int error_code() const { return error_code_; }

 private:
  const char * routine_;
  int error_code_;
  std::string description_;
};


#define QHIPSTER_MPI_CHECK_RESULT(MPIFunc, Args)                                           \
  {                                                                                        \
    int check_result = MPIFunc Args;                                                       \
    if (check_result != MPI_SUCCESS) throw qhipster::mpi::Exception(#MPIFunc,check_result);\
  }


}   // end namespace mpi
}   // end namespace qhipster


#endif  // header guard IQS_MPI_EXCEPTION_HPP