reduction_expr

One reduction of a parallel loop.

Declaration

Syntax

reduction_expr = (reduction_op op, expr arg)

Arguments

Argument

Description

op

the operator values are combined with; see reduction_op.

arg

the variable the result is accumulated into.

Return values

None.

Description

Each iteration accumulates into its own copy of arg, and the copies are combined with op when the loop ends. The operators are associative, which is what makes the order the copies are combined in irrelevant.

Examples

(reduction_expr
  :op :ReduceAdd
  :arg (Var
    :v (SymbolRef 1 "total")
  )
)

It comes from this complete ASR text document:

(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
              )
              :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 []
)

See Also

DoConcurrentLoop, reduction_op, OMPReduction