L::MPI::MPI(int *argc, char ***argv) { int initialized; int status = MPI_Initialized (&initialized); if (status != MPI_SUCCESS || initialized) throw MPIError(status); status = MPI_Init (argc, argv); if (status != MPI_SUCCESS) throw MPIError(status); status = MPI_Comm_rank (MPI_COMM_WORLD, &rank); if (status != MPI_SUCCESS) { MPI_Finalize(); throw MPIError(status); } }
MPIError MPIError::from_code(const int err_code) { char err_str[MPI_MAX_ERROR_STRING]; int err_len = 0; int err = MPI_Error_string(err_code, err_str, &err_len); check_mpi_error(err); return MPIError("MPI Error: " + string(err_str, err_len) + " (code=" + to_string(err_code) + ")"); }
void MPI_err_handler(MPI_Comm *, int *err_code, ...){ char *err_string=new char[MPI_MAX_ERROR_STRING]; int err_length; MPI_Error_string(*err_code, err_string, &err_length); std::string s(err_string, err_length); std::cerr << "An MPI Error ocurred:"<<std::endl<<s<<std::endl; delete[] err_string; throw MPIError(s, *err_code); }
L::MPI::~MPI () { int status = MPI_Finalize(); if (status != MPI_SUCCESS) throw MPIError(status); }