Skip to content

Commit

Permalink
V2.6.x disort error fix (#782)
Browse files Browse the repository at this point in the history
Add exception handling in DISORT OMP-loop
  • Loading branch information
riclarsson authored Jun 21, 2024
2 parents 1576f9a + 3b060f1 commit a55aa6d
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/disort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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
Expand Down Expand Up @@ -1764,9 +1772,17 @@ 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);
} 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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a55aa6d

Please sign in to comment.