Skip to content

Commit

Permalink
[CPU][OMP] Handle exception outside parallel region
Browse files Browse the repository at this point in the history
  • Loading branch information
nshchego committed Oct 29, 2024
1 parent e07546d commit c1a40fd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/plugins/intel_cpu/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,23 +1286,40 @@ class UpdateNodes : public UpdateNodesBase {
if (origin_nested_levels < 2) {
set_max_nested_levels(2);
}
// In OpenMP, an exception that is thrown in a parallel region must be caught and handled in the same region by the same thread.
// Therefore, need to pass the error message and throw a new exception outside the parallel region.
const char* what = nullptr;

#pragma omp parallel
#pragma omp sections
{
#pragma omp section
{
updateDynParams(startCounter, stopIndx);
try{
updateDynParams(startCounter, stopIndx);
} catch (std::exception& e) {
what = e.what();
} catch (...) {
what = "[ CPU ] Could not update dynamic parameters.";
}
}
#pragma omp section
{
updateShapes(startCounter, stopIndx);
try {
updateShapes(startCounter, stopIndx);
} catch (std::exception& e) {
what = e.what();
} catch (...) {
what = "[ CPU ] Could not update shapes.";
}
}
}

if (origin_nested_levels != 2) {
set_max_nested_levels(origin_nested_levels);
}

OPENVINO_ASSERT(what == nullptr, what);
}
};
#endif
Expand Down

0 comments on commit c1a40fd

Please sign in to comment.