Package jromp.var

Class ReductionVariable<T extends Serializable>

java.lang.Object
jromp.var.ReductionVariable<T>
Type Parameters:
T - the type of the variable.
All Implemented Interfaces:
Serializable, Variable<T>

public class ReductionVariable<T extends Serializable> extends Object implements Variable<T>
Represents a reduction variable that its value is reduced from "custom" thread-local variables using a reduction operation.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReductionVariable(ReductionOperation<T> operation, T initialValue)
    Constructs a new reduction variable with the given reduction operation and initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    end()
    Performs any cleanup operations that may be required by the variable.
    boolean
    Indicates whether the reduction variable has been merged.
    void
    Merges the private variables of the threads to the result of the reduction operation.
    void
    set(T value)
    Sets the value of the variable.
     
    void
    update(UnaryOperator<T> operator)
    Applies the given UnaryOperator to update the value of the variable.
    Retrieves the value of the variable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface jromp.var.Variable

    update
  • Constructor Details

    • ReductionVariable

      public ReductionVariable(ReductionOperation<T> operation, T initialValue)
      Constructs a new reduction variable with the given reduction operation and initial value.

      Note: The value of the "private" variables is initialized to the default initial value of the reduction variable.

      Parameters:
      operation - the reduction operation.
      initialValue - the initial value of the reduction variable.
  • Method Details

    • value

      public T value()
      Description copied from interface: Variable
      Retrieves the value of the variable.
      Specified by:
      value in interface Variable<T extends Serializable>
      Returns:
      the value of the variable.
    • set

      public void set(T value)
      Description copied from interface: Variable
      Sets the value of the variable.
      Specified by:
      set in interface Variable<T extends Serializable>
      Parameters:
      value - the new value to be set.
    • update

      public void update(UnaryOperator<T> operator)
      Description copied from interface: Variable
      Applies the given UnaryOperator to update the value of the variable.
      Specified by:
      update in interface Variable<T extends Serializable>
      Parameters:
      operator - the unary operator to apply.
    • end

      public void end()
      Description copied from interface: Variable
      Performs any cleanup operations that may be required by the variable.
      Specified by:
      end in interface Variable<T extends Serializable>
    • isMerged

      public boolean isMerged()
      Indicates whether the reduction variable has been merged.
      Returns:
      true if the reduction variable has been merged; false otherwise.
    • merge

      public void merge()
      Merges the private variables of the threads to the result of the reduction operation.
    • toString

      public String toString()
      Overrides:
      toString in class Object