From e64f8884f4bd24637dcdaa101e8944fb9f450034 Mon Sep 17 00:00:00 2001 From: Manfred Brath Date: Wed, 19 Jun 2024 15:16:35 +0200 Subject: [PATCH 1/2] Add exception handling in DISORT OMP-loop --- src/disort.cc | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/disort.cc b/src/disort.cc index c76277fb47..db27fdd526 100644 --- a/src/disort.cc +++ b/src/disort.cc @@ -1565,6 +1565,9 @@ void run_cdisort_flux(Workspace& ws, nlinspace(pfct_angs, 0, 180, nang); } + ArrayOfString fail_msg; + bool do_abort = false; + WorkspaceOmpParallelCopyGuard wss{ws}; // start loop over all frequencies #pragma omp parallel for if (!arts_omp_in_parallel() && f_grid.nelem() > 1) \ @@ -1580,6 +1583,11 @@ void run_cdisort_flux(Workspace& ws, dtauc, \ out) for (Index f_index = 0; f_index < f_grid.nelem(); f_index++) { + + if (do_abort) { + continue; + } + Vector f_grid_i(1); //Intensity of incident sun beam @@ -1764,7 +1772,15 @@ void run_cdisort_flux(Workspace& ws, ds.bc.umu0 = umu0; tries = Status::RETRY; } else - throw e; + { +#pragma omp critical(run_cdisort_flux_setabort) + do_abort = true; + + ostringstream os; + os << "failure at f_index " << f_index << ":\n" << e.what(); +#pragma omp critical(ybatchCalc_push_fail_msg) + fail_msg.push_back(os.str()); + } } } while (tries != Status::SUCCESS); @@ -1827,6 +1843,17 @@ void run_cdisort_flux(Workspace& ws, c_disort_state_free(&ds); } + if (fail_msg.nelem()) { + ostringstream os; + + if (!do_abort) os << "\nError messages from failed run_cdisort_flux:\n"; + for (ArrayOfString::const_iterator it = fail_msg.begin(); + it != fail_msg.end(); + it++) + os << *it << '\n'; + throw runtime_error(os.str()); + } + // Allocate aux data disort_aux.resize(disort_aux_vars.nelem()); // Allocate and set (if possible here) iy_aux From 3b060f1633b05037e327aa66d0a6e7738482a6c0 Mon Sep 17 00:00:00 2001 From: Manfred Brath Date: Wed, 19 Jun 2024 16:29:24 +0200 Subject: [PATCH 2/2] Add bugfix for infinite loop --- src/disort.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/disort.cc b/src/disort.cc index db27fdd526..b2b7d0a465 100644 --- a/src/disort.cc +++ b/src/disort.cc @@ -1782,7 +1782,7 @@ void run_cdisort_flux(Workspace& ws, fail_msg.push_back(os.str()); } } - } while (tries != Status::SUCCESS); + } while (tries != Status::SUCCESS and not do_abort); //factor for converting it into spectral radiance units const Numeric conv_fac = (ds.wvnmhi - ds.wvnmlo) * (100 * SPEED_OF_LIGHT);