From f4876becfb7b099e96e85841524b15a455fadf90 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 9 Mar 2020 10:40:45 +0100 Subject: [PATCH] Improve exception handling in ParallelEclipseState::get_global-* In particular we make sure that all processes throw on unknown keywords. --- opm/simulators/utils/ParallelEclipseState.cpp | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/opm/simulators/utils/ParallelEclipseState.cpp b/opm/simulators/utils/ParallelEclipseState.cpp index b7db316d1..8b88182ca 100644 --- a/opm/simulators/utils/ParallelEclipseState.cpp +++ b/opm/simulators/utils/ParallelEclipseState.cpp @@ -74,8 +74,26 @@ const std::vector& ParallelFieldPropsManager::get_int(const std::string& ke std::vector ParallelFieldPropsManager::get_global_int(const std::string& keyword) const { std::vector result; + int exceptionThrown{}; + if (m_comm.rank() == 0) - result = m_manager.get_global_int(keyword); + { + try + { + result = m_manager.get_global_int(keyword); + }catch(std::exception& e) { + exceptionThrown = 1; + OpmLog::error("No integer property field: " + keyword + " ("+e.what()+")"); + m_comm.broadcast(&exceptionThrown, 1, 0); + throw e; + } + } + + m_comm.broadcast(&exceptionThrown, 1, 0); + + if (exceptionThrown) + OPM_THROW_NOLOG(std::runtime_error, "No integer property field: " + keyword); + size_t size = result.size(); m_comm.broadcast(&size, 1, 0); result.resize(size); @@ -98,8 +116,26 @@ const std::vector& ParallelFieldPropsManager::get_double(const std::stri std::vector ParallelFieldPropsManager::get_global_double(const std::string& keyword) const { std::vector result; + int exceptionThrown{}; + if (m_comm.rank() == 0) - result = m_manager.get_global_double(keyword); + { + try + { + result = m_manager.get_global_double(keyword); + }catch(std::exception& e) { + exceptionThrown = 1; + OpmLog::error("No double property field: " + keyword + " ("+e.what()+")"); + m_comm.broadcast(&exceptionThrown, 1, 0); + throw e; + } + } + + m_comm.broadcast(&exceptionThrown, 1, 0); + + if (exceptionThrown) + OPM_THROW_NOLOG(std::runtime_error, "No double property field: " + keyword); + size_t size = result.size(); m_comm.broadcast(&size, 1, 0); result.resize(size);