Package ffx.numerics.atomic
Class MultiDoubleArray
java.lang.Object
ffx.numerics.atomic.MultiDoubleArray
- All Implemented Interfaces:
AtomicDoubleArray
The MultiDoubleArray avoids the need for Atomic variables, but at the cost of storing a full size
double array for each thread.
- Since:
- 1.0
- Author:
- Michael J. Schnieders
-
Nested Class Summary
Nested classes/interfaces inherited from interface ffx.numerics.atomic.AtomicDoubleArray
AtomicDoubleArray.AtomicDoubleArrayImpl
-
Constructor Summary
ConstructorsConstructorDescriptionMultiDoubleArray
(int threadCount, int arraySize) Constructor for MultiDoubleArray. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int threadID, int index, double value) Add a value to the double array at the specified index.void
alloc
(int arraySize) 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 lb, int ub) Reduce contributions from each thread into the main thread's array.void
reduce
(ParallelTeam parallelTeam, int lb, int ub) Perform reduction between the given bounds using a ParallelTeam.void
reset
(int threadID, int lb, int ub) Reset the double array values to zero within the specified bounds.void
reset
(ParallelTeam parallelTeam, int lb, int ub) 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
size()
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.
-
Constructor Details
-
MultiDoubleArray
public MultiDoubleArray(int threadCount, int arraySize) Constructor for MultiDoubleArray.- Parameters:
threadCount
- the number of threads.arraySize
- the 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 interfaceAtomicDoubleArray
- Parameters:
threadID
- The thread ID.index
- The index of the array.value
- The value to add.
-
alloc
public void alloc(int arraySize) Ensure the AtomicDoubleArray instance has at least the specified size.- Specified by:
alloc
in interfaceAtomicDoubleArray
- Parameters:
arraySize
- 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 interfaceAtomicDoubleArray
- Parameters:
index
- The index of the array.- Returns:
- The value at the specified index.
-
reduce
public void reduce(int lb, int ub) Reduce contributions from each thread into the main thread's array.- Specified by:
reduce
in interfaceAtomicDoubleArray
- Parameters:
lb
- lower bound index.ub
- upper bound index.
-
reduce
Perform reduction between the given bounds using a ParallelTeam.- Specified by:
reduce
in interfaceAtomicDoubleArray
- Parameters:
parallelTeam
- The ParallelTeam to use.lb
- The lower bound of the range.ub
- The upper bound of the range.
-
reset
public void reset(int threadID, int lb, int ub) Reset the double array values to zero within the specified bounds.- Specified by:
reset
in interfaceAtomicDoubleArray
- Parameters:
threadID
- The thread ID.lb
- The lower bound of the reset range.ub
- The upper bound of the reset range.
-
reset
Reset the double array values to zero within the specified bounds using a ParallelTeam.- Specified by:
reset
in interfaceAtomicDoubleArray
- Parameters:
parallelTeam
- The ParallelTeam to use.lb
- The lower bound of the reset range.ub
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- Parameters:
threadID
- The thread ID.index
- The index of the array.value
- The value to subtract.
-