Class PJDoubleArray

java.lang.Object
ffx.numerics.atomic.PJDoubleArray
All Implemented Interfaces:
AtomicDoubleArray

public class PJDoubleArray extends Object implements AtomicDoubleArray
PJDoubleArray implements the AtomicDoubleArray interface using the Parallel Java class SharedDoubleArray.

SharedDoubleArray is multiple thread safe and uses lock-free atomic compare-and-set.

Note: Class SharedDoubleArray is implemented using class java.util.concurrent.atomic.AtomicLongArray. Each double array element is stored as a long whose bit pattern is the same as the double value.

Since:
1.0
Author:
Michael J. Schnieders
  • Nested Class Summary

    Nested classes/interfaces inherited from interface ffx.numerics.atomic.AtomicDoubleArray

    AtomicDoubleArray.AtomicDoubleArrayImpl
  • Constructor Summary

    Constructors
    Constructor
    Description
    PJDoubleArray(int arraySize)
    Constructor: Initialize the size and array.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int threadID, int index, double value)
    Add a value to the double array at the specified index.
    void
    alloc(int newSize)
    Ensure the AtomicDoubleArray instance has at least the specified size.
    double
    get(int index)
    Get the value of the array at the specified index.
    void
    reduce(int lowerBound, int upperBound)
    Perform reduction between the given lower and upper bounds, if necessary.
    void
    reduce(ParallelTeam parallelTeam, int lowerBound, int upperBound)
    Perform reduction between the given bounds using a ParallelTeam.
    void
    reset(int threadID, int lowerBound, int upperBound)
    Reset the double array values to zero within the specified bounds.
    void
    reset(ParallelTeam parallelTeam, int lowerBound, int upperBound)
    Reset the double array values to zero within the specified bounds using a ParallelTeam.
    void
    scale(int threadID, int index, double value)
    Scale the value of the double array at the specified index.
    void
    set(int threadID, int index, double value)
    Set the value of the double array at the specified index.
    int
    Get the current size of the array.
    void
    sub(int threadID, int index, double value)
    Subtract a value from the double array at the specified index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PJDoubleArray

      public PJDoubleArray(int arraySize)
      Constructor: Initialize the size and array.
      Parameters:
      arraySize - the desired size of the array.
  • Method Details

    • add

      public void add(int threadID, int index, double value)
      Add a value to the double array at the specified index.
      Specified by:
      add in interface AtomicDoubleArray
      Parameters:
      threadID - The thread ID.
      index - The index of the array.
      value - The value to add.
    • alloc

      public void alloc(int newSize)
      Ensure the AtomicDoubleArray instance has at least the specified size.
      Specified by:
      alloc in interface AtomicDoubleArray
      Parameters:
      newSize - The required size of the array.
    • get

      public double get(int index)
      Get the value of the array at the specified index. Note: The `reduce` method should be called first when using the MULTI implementation.
      Specified by:
      get in interface AtomicDoubleArray
      Parameters:
      index - The index of the array.
      Returns:
      The value at the specified index.
    • reduce

      public void reduce(int lowerBound, int upperBound)
      Perform reduction between the given lower and upper bounds, if necessary.
      Specified by:
      reduce in interface AtomicDoubleArray
      Parameters:
      lowerBound - The lower bound of the range.
      upperBound - The upper bound of the range.
    • reduce

      public void reduce(ParallelTeam parallelTeam, int lowerBound, int upperBound)
      Perform reduction between the given bounds using a ParallelTeam.
      Specified by:
      reduce in interface AtomicDoubleArray
      Parameters:
      parallelTeam - The ParallelTeam to use.
      lowerBound - The lower bound of the range.
      upperBound - The upper bound of the range.
    • reset

      public void reset(int threadID, int lowerBound, int upperBound)
      Reset the double array values to zero within the specified bounds.
      Specified by:
      reset in interface AtomicDoubleArray
      Parameters:
      threadID - The thread ID.
      lowerBound - The lower bound of the reset range.
      upperBound - The upper bound of the reset range.
    • reset

      public void reset(ParallelTeam parallelTeam, int lowerBound, int upperBound)
      Reset the double array values to zero within the specified bounds using a ParallelTeam.
      Specified by:
      reset in interface AtomicDoubleArray
      Parameters:
      parallelTeam - The ParallelTeam to use.
      lowerBound - The lower bound of the reset range.
      upperBound - The upper bound of the reset range.
    • scale

      public void scale(int threadID, int index, double value)
      Scale the value of the double array at the specified index.
      Specified by:
      scale in interface AtomicDoubleArray
      Parameters:
      threadID - The thread ID.
      index - The index of the array.
      value - The value to scale by.
    • set

      public void set(int threadID, int index, double value)
      Set the value of the double array at the specified index.
      Specified by:
      set in interface AtomicDoubleArray
      Parameters:
      threadID - The thread ID.
      index - The index of the array.
      value - The value to set.
    • size

      public int size()
      Get the current size of the array.
      Specified by:
      size in interface AtomicDoubleArray
      Returns:
      The size of the array.
    • sub

      public void sub(int threadID, int index, double value)
      Subtract a value from the double array at the specified index.
      Specified by:
      sub in interface AtomicDoubleArray
      Parameters:
      threadID - The thread ID.
      index - The index of the array.
      value - The value to subtract.