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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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) Perform reduction between the given lower bound (lb) and upper bound (up) if necessary.void
reduce
(ParallelTeam parallelTeam, int lb, int ub) Perform reduction between the given lower bound (lb) and upper bound (up) using a ParallelTeam.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
size()
Get the size of the array.void
sub
(int threadID, int index, double value) Subtract value to the double array at the specified index.
-
Constructor Details
-
MultiDoubleArray
public MultiDoubleArray(int nThreads, int size) Constructor for MultiDoubleArray.- Parameters:
nThreads
- the number of threads.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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- Parameters:
size
- The size of the array.
-
get
public double get(int index) Get the value of the array at the specified index. Thereduce
method should be called first when using the MULTI implementation.- Specified by:
get
in interfaceAtomicDoubleArray
- Parameters:
index
- the index.- Returns:
- the value of the array at the specified index.
-
reduce
public void reduce(int lb, int ub) Perform reduction between the given lower bound (lb) and upper bound (up) if necessary.Reduce the contributions from each thread into array[0];
- Specified by:
reduce
in interfaceAtomicDoubleArray
- Parameters:
lb
- the lower bound.ub
- the upper bound.
-
reduce
Perform reduction between the given lower bound (lb) and upper bound (up) using a ParallelTeam.Reduce the contributions from each thread into array[0];
- Specified by:
reduce
in interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- Parameters:
threadID
- the thread ID.lb
- the lower bound.ub
- the upper bound.
-
reset
Reset the double array to Zero using a ParallelTeam.- Specified by:
reset
in interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- 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 interfaceAtomicDoubleArray
- Parameters:
threadID
- the thread ID.index
- the index.value
- the value to subtract.
-