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 size)
    Constructor for PJDoubleArray.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int threadID, int index, double value)
    Add value to the double array at the specified index.
    void
    alloc(int size)
    Ensure the AtomicDoubleArray instance is greater than or equal to size.
    double
    get(int index)
    Get the value of the array at the specified index.
    void
    reduce(int lb, int ub)
    Reduction is handled atomically by the PJ SharedDoubleArray, so this method does nothing.
    void
    reduce(ParallelTeam parallelTeam, int lb, int ub)
    Reduction is handled atomically by the PJ SharedDoubleArray, so this method does nothing.
    void
    reset(int threadID, int lb, int ub)
    Reset the double array to Zero.
    void
    reset(ParallelTeam parallelTeam, int lb, int ub)
    Reset the double array to Zero using a ParallelTeam.
    void
    scale(int threadID, int index, double value)
    Scale the double array at the specified index by the given value.
    void
    set(int threadID, int index, double value)
    Set the double array at the specified index to the given value.
    int
    Get the size of the array.
    void
    sub(int threadID, int index, double value)
    Subtract value to 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 size)
      Constructor for PJDoubleArray.
      Parameters:
      size - the size of the array.
  • Method Details

    • add

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

      public void alloc(int size)
      Ensure the AtomicDoubleArray instance is greater than or equal to size.
      Specified by:
      alloc in interface AtomicDoubleArray
      Parameters:
      size - The size of the array.
    • get

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

      public void reduce(int lb, int ub)
      Reduction is handled atomically by the PJ SharedDoubleArray, so this method does nothing.
      Specified by:
      reduce in interface AtomicDoubleArray
      Parameters:
      lb - the lower bound.
      ub - the upper bound.
    • reduce

      public void reduce(ParallelTeam parallelTeam, int lb, int ub)
      Reduction is handled atomically by the PJ SharedDoubleArray, so this method does nothing.
      Specified by:
      reduce in interface AtomicDoubleArray
      Parameters:
      parallelTeam - ParallelTeam to use.
      lb - the lower bound.
      ub - the upper bound.
    • reset

      public void reset(int threadID, int lb, int ub)
      Reset the double array to Zero.
      Specified by:
      reset in interface AtomicDoubleArray
      Parameters:
      threadID - the thread ID.
      lb - the lower bound.
      ub - the upper bound.
    • reset

      public void reset(ParallelTeam parallelTeam, int lb, int ub)
      Reset the double array to Zero using a ParallelTeam.
      Specified by:
      reset in interface AtomicDoubleArray
      Parameters:
      parallelTeam - ParallelTeam to use.
      lb - the lower bound.
      ub - the upper bound.
    • scale

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

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

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

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