psyclone.psyir.transformations.increase_rank_loop_arrays_trans#
This module contains the IncreaseRankLoopArrays transformation.
Classes#
IncreaseRankLoopArraysTrans: This transformation takes a loop and a list of arrays accessed inside
- class psyclone.psyir.transformations.increase_rank_loop_arrays_trans.IncreaseRankLoopArraysTrans[source]#
This transformation takes a loop and a list of arrays accessed inside the loop, and increases those arrays with an additional dimension with the size of the interation space. Then it indexes all accesses with the loop variable, so that each iteration accesses a unique location. Effectively making the sub-array private for each iteration of the loop. It also indexes assignments outside the loop to iterate over the whole new rank.
>>> from psyclone.psyir.backend.fortran import FortranWriter >>> from psyclone.psyir.frontend.fortran import FortranReader >>> from psyclone.psyir.nodes import Loop >>> from psyclone.psyir.transformations import IncreaseRankLoopArraysTrans >>> code = (""" ... program test ... integer :: N=10, M=10 ... integer :: i, j ... real, dimension(N) :: ztmp ... ! (Array) Assignments to the target variable outside the loop are ... ! permited, but any other use will not pass the validation ... ztmp = 0 ... ztmp(0) = 1 ... do i = -5, M + 3 ... do j = 1, N ... ztmp(j) = 1 ... end do ... do j = 1, N ... ztmp(j) = ztmp(j) + 1 ... end do ... end do ... end program ... """) >>> psyir = FortranReader().psyir_from_source(code) >>> irla = IncreaseRankLoopArraysTrans() >>> irla.apply(psyir.walk(Loop)[0], arrays=['ztmp']) >>> print(FortranWriter()(psyir)) program test integer, save :: n = 10 integer, save :: m = 10 integer :: i integer :: j real, dimension(n,-5:m + 3) :: ztmp ztmp = 0 ztmp(0,:) = 1 do i = -5, m + 3, 1 do j = 1, n, 1 ztmp(j,i) = 1 enddo do j = 1, n, 1 ztmp(j,i) = ztmp(j,i) + 1 enddo enddo end program test
Inheritance

- validate(node, **kwargs)[source]#
Checks that the supplied node is a valid target.
- Parameters:
node (
Loop) – target Loop node.arrays (list[psyclone.psyir.symbols.symbol.Symbol | str] | None) – list of arrays that will have their rank increased.
- Raises:
TransformationError – if the node is not a Loop.
TransformationError – if the node is not inside a Routine.
TransformationError – if the target node does not have static loop bounds (which the dimension declaration needs).
TransformationError – if no array names are provided.
TransformationError – the given array name or the symbol is not local or not an array.
TransformationError – if any of the arrays are referenced inside a CodeBlock.
TransformationError – if any of the arrays are referenced outside the loop in anything other than (array) assignments to their variable.