psyclone.psyir.transformations.parallel_loop_trans#
This module provides the ParallelLoopTrans transformation.
Classes#
ParallelLoopTrans: Adds an abstract directive (it needs to be specified by sub-classing this
- class psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans[source]#
Adds an abstract directive (it needs to be specified by sub-classing this transformation) to a loop indicating that it should be parallelised. It performs some data dependency checks to guarantee that the loop can be parallelised without changing the semantics of it.
If the nowait option is supplied to the apply function, then PSyclone will attempt to add the relevant asynchronous option to the directive, if supported. If its not supported, or PSyclone’s analysis suggests that it cannot be launched asynchronously, the transformation will occur as though the nowait option was not supplied. If the asynchronous option is added, PSyclone will also generate a corresponding barrier before the next dependent statement.
Inheritance

- apply(node, options=None, verbose=False, collapse=False, force=False, ignore_dependencies_for=None, privatise_arrays=False, sequential=False, nowait=False, reduction_ops=None, **kwargs)[source]#
Apply the Loop transformation to the specified node in a Schedule. This node must be a Loop since this transformation corresponds to wrapping the generated code with directives, e.g. for OpenMP:
!$OMP DO do ... ... end do !$OMP END DO
At code-generation time (when lowering is called), this node must be within (i.e. a child of) a PARALLEL region.
- Parameters:
node (
psyclone.psyir.nodes.Node) – the supplied node to which we will apply the loop parallelisation transformation.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
collapse (
Union[int,bool]) – if it’s a bool and is False (default), it won’t collapse. If it’s a bool and is True, it will collapse as much as possible. If it’s an integer, it will attempt to collapse until the specified number of loops (if they exist and are safe to collapse them). The options ‘ignore_dependencies_for’ and ‘force’ also affect the collapse applicability analysis.force (
bool) – whether to force parallelisation of the target loop (i.e. ignore any dependence analysis).ignore_dependencies_for (
Optional[List[str]]) – whether to ignore some symbol names from the dependence analysis checks.sequential (
bool) – whether this is a sequential loop.verbose (
bool) – whether to report the reasons the validate and collapse steps have failed.nowait (
bool) – whether to add a nowait clause and a corresponding barrier (or equivalent) to enable asynchronous execution.privatise_arrays (
bool) – whether to make the write after write dependency symbols declared as private.reduction_ops (
List[Union[Operator,Intrinsic]]) – if non-empty, attempt parallelisation of loops by inferring reduction clauses involving any of the reduction operators in the list.node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.
- validate(node, options=None, **kwargs)[source]#
Perform validation checks before applying the transformation
- Parameters:
node (
psyclone.psyir.nodes.Node) – the supplied node to which we will apply the loop parallelisation transformation.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
collapse (int | bool) – if it’s a bool and is False (default), it won’t collapse. If it’s a bool and is True, it will collapse as much as possible. If it’s an integer, it will attempt to collapse until the specified number of loops (if they exist and are safe to collapse them). The options ‘ignore_dependencies_for’ and ‘force’ also affect the collapse applicability analysis.
force (bool) – whether to force parallelisation of the target loop (i.e. ignore any dependence analysis).
ignore_dependencies_for (None | List[str]) – whether to ignore some symbol names from the dependence analysis checks.
sequential (bool) – whether this is a sequential loop.
verbose (bool) – whether to report the reasons the validate and collapse steps have failed.
nowait (bool) – whether to add a nowait clause and a corresponding barrier (or equivalent) to enable asynchronous execution.
privatise_arrays (bool) – whether to make the write after write dependency symbols declared as private.
reduction_ops (List[psyclone.psyir.nodes.operation.Operator | psyclone.psyir.nodes.intrinsic_call.IntrinsicCall.Intrinsic]) – if non-empty, attempt parallelisation of loops by inferring reduction clauses involving any of the reduction operators in the list.
node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.
reprod (bool) – indicating whether reproducible reductions should be used. By default the value from the config file will be used.
enable_reductions (bool) – whether to attempt to infer reduction clauses or not.
- Raises:
TypeError – if ‘collapse’ is not an int or a bool.
TypeError – if ‘ignore_dependencies_for’ is not a list of str.
TransformationError – if the given loop iterates over a colours (LFRic domain) iteration space.
TransformationError – if the given loops calls a procedure that is not guaranteed to be pure (and therefore could have dependencies beyond the specified by the arguments intent)
TransformationError – if the given loop is inside a pure routine as these do not allow parallel constructs.
TransformationError – if there is a data dependency that prevents the parallelisation of the loop and the provided options don’t disregard them.