| 1 | /* |
| 2 | * MPI_util.hpp |
| 3 | * |
| 4 | * Created on: Jul 7, 2015 |
| 5 | * Author: Pietro Incardona |
| 6 | */ |
| 7 | |
| 8 | #ifndef MPI_UTIL_HPP_ |
| 9 | #define MPI_UTIL_HPP_ |
| 10 | |
| 11 | #include <iostream> |
| 12 | |
| 13 | /*! \brief From an MPI error it print an human readable message |
| 14 | * |
| 15 | * \param error_code |
| 16 | * |
| 17 | */ |
| 18 | static void error_handler(int error_code) |
| 19 | { |
| 20 | int rank; |
| 21 | char error_string[BUFSIZ]; |
| 22 | int length_of_error_string, error_class; |
| 23 | |
| 24 | MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
| 25 | |
| 26 | MPI_Error_class(error_code, &error_class); |
| 27 | MPI_Error_string(error_class, error_string, &length_of_error_string); |
| 28 | std::cerr << rank << ": " << error_string; |
| 29 | MPI_Error_string(error_code, error_string, &length_of_error_string); |
| 30 | std::cerr << rank << ": " << error_string; |
| 31 | } |
| 32 | |
| 33 | #define MPI_SAFE_CALL(call) {\ |
| 34 | int err = call;\ |
| 35 | if (MPI_SUCCESS != err) {\ |
| 36 | std::cerr << "MPI error: "<< __FILE__ << " " << __LINE__ << "\n";\ |
| 37 | error_handler(err);\ |
| 38 | MPI_Abort(MPI_COMM_WORLD,-1);\ |
| 39 | }\ |
| 40 | } |
| 41 | |
| 42 | |
| 43 | #endif /* MPI_UTIL_HPP_ */ |
| 44 | |