# loki.transformations.split_read_write

Classes

`SplitReadWriteTransformation`(dimensions) | When accumulating values to multiple components of an array, a compiler cannot rule out the possibility that the indices alias the same address.
`SplitReadWriteWalk`(dimensions, variable_map) | A `Transformer` class to traverse the IR, in-place replace read-write assignments with reads, and build a transformer map for the corresponding writes.

class SplitReadWriteTransformation(dimensions)

  Bases: `Transformation`

  When accumulating values to multiple components of an array, a compiler cannot rule out the possibility that the indices alias the same address. Consider for example the following code:

      !$loki split-read-write
      do jlon=1,nproma
         var(jlon, n1) = var(jlon, n1) + 1.
         var(jlon, n2) = var(jlon, n2) + 1.
      enddo
      !$loki end split-read-write

  In the above example, there is no guarantee that `n1` and `n2` do not in fact point to the same location. Therefore the load and store instructions for `var` have to be executed in order.

  For cases where the user knows `n1` and `n2` indeed represent distinct locations, this transformation provides a pragma assisted mechanism to split the reads and writes, and therefore make the loads independent from the stores. The above code would therefore be transformed to:

      !$loki split-read-write
      do jlon=1,nproma
         loki_temp_0(jlon) = var(jlon, n1) + 1.
         loki_temp_1(jlon) = var(jlon, n2) + 1.
      enddo

      do jlon=1,nproma
         var(jlon, n1) = loki_temp_0(jlon)
         var(jlon, n2) = loki_temp_1(jlon)
      enddo
      !$loki end split-read-write

  Parameters:

    dimensions (list) – A list of `Dimension` objects corresponding to all `Loop`s in the ``!$loki split-read-write`` region.

  item_filter = (<class 'loki.batch.item.ProcedureItem'>,)
  transform_subroutine(routine, **kwargs)

    Defines the transformation to apply to `Subroutine` items.

    For transformations that modify `Subroutine` objects, this method should be implemented. It gets called via the dispatch method `apply()`.

    Parameters:

      - routine (`Subroutine`) – The subroutine to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.