DoConcurrentLoop

A loop whose iterations may run in any order.

Declaración

Sintaxis

DoConcurrentLoop(do_loop_head* head, expr* shared, expr* local,
    reduction_expr* reduction, stmt* body)

Argumentos

Argument

Descripción

head

one do_loop_head per index, giving the index variable and its range. Several heads mean a nest of concurrent indices.

shared

the variables shared by all iterations.

local

the variables each iteration has its own copy of.

reduction

the reductions, each a reduction_expr pairing an operator with the variable it accumulates into.

body

the statements of one iteration.

Valores devueltos

None.

Descripción

do concurrent asserts that the iterations do not depend on each other, so a backend may run them in any order or in parallel. ASR records the assertion and the data environment; it does not check it.

The locality lists say what each iteration sees. A variable in local is private to an iteration, a variable in shared is not, and a variable in reduction is combined across iterations with the named operator.

Every parallel loop is said one way before anything decides how to lower it, and that way is an OMPRegion: the parallel_canonicalize pass rewrites a do concurrent loop, an !$omp target region and, when the compiler is asked to offload them, an !$omp parallel do into one canonical region carrying OMPIndependent – the assertion this loop makes. exec_target on that region then carries the lowering decision for that one loop, so a program may mix serial, host-threaded and device loops.

Only the outermost loop of a nest becomes a region, so a concurrent loop left in the body keeps this node and runs its iterations in order inside the thread that reached it. Passes that run after the parallel pipeline, such as forall and array_struct_temporary, also build this node; do_loops lowers all of them into an ordinary loop nest.

Ejemplos

An ASR text document that uses it:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "a" (Variable
              :parent_symtab 1
              :name "a"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Array
                :type (Integer
                  :kind 4
                )
                :dims [
                  (dimension
                    :start (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :length (IntegerConstant
                      :n 3
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                  )
                ]
                :physical_type :FixedSizeArray
                :memory_space :Global
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "i" (Variable
              :parent_symtab 1
              :name "i"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "total" (Variable
              :parent_symtab 1
              :name "total"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (DoConcurrentLoop
            :head [
              (do_loop_head
                :v (Var
                  :v (SymbolRef 1 "i")
                )
                :start (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :end (IntegerConstant
                  :n 3
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :increment (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              )
            ]
            :shared [
              (Var
                :v (SymbolRef 1 "a")
              )
            ]
            :local [
              (Var
                :v (SymbolRef 1 "i")
              )
            ]
            :reduction [
              (reduction_expr
                :op :ReduceAdd
                :arg (Var
                  :v (SymbolRef 1 "total")
                )
              )
            ]
            :body [
              (Assignment
                :target (ArrayItem
                  :v (Var
                    :v (SymbolRef 1 "a")
                  )
                  :args [
                    (array_index
                      :left nil
                      :right (Var
                        :v (SymbolRef 1 "i")
                      )
                      :step nil
                    )
                  ]
                  :type (Integer
                    :kind 4
                  )
                  :storage_format :ColMajor
                  :value nil
                )
                :value (Var
                  :v (SymbolRef 1 "i")
                )
                :overloaded nil
                :realloc_lhs false
                :move_allocation false
              )
            ]
          )
        ]
      )
    }
  )
  :items []
)

Ver también

DoLoop, OMPRegion, do_loop_head, reduction_expr, exec_target