Skip to content

Make ACTFW_PARALLEL_FOR easier to use and to maintain

OpenMP has annoying limitations pertaining to control flow, which prevent things like breaking out of a parallel loop, returning early from the function where the loop is located, or throwing exceptions. The problem is that in ACTS, we currently need both early return and exception propagation for error handling.

As a workaround, the ACTFW_PARALLEL_FOR macro was created. What it does is basically to create an OpenMP parallel loop which executes the user code inside of a wrapper that catches "unwanted" control flow and handles it in an OpenMP friendly way.

But so far, the wrapper was neither very easy to use (as some standard C++ control flow still had to be replaced with custom macros) nor easy to maintain (as it was entirely implemented using macros, which are notoriously hard to write).

This MR is an attempt to rewrite ACTFW_PARALLEL_FOR in such a way that it accepts almost^[1] all the standard C++ loop control flow constructs in the loop iteration code (which makes it easier to use) and that it is mostly implemented using normal C++ code, relegating macros to those few tasks where they are strictly necessary (which makes the code easier to maintain).

Accepting this fixes ACTSFW-89.


[1] Sorry, goto fans. Your favorite evil trick does not mix well with macro-based code generation.

Edited by Hadrien Benjamin Grasland

Merge request reports