|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.pj.reduction.SharedLongMatrix
public class SharedLongMatrix
Class SharedLongMatrix provides a matrix reduction variable with elements of type long.
Class SharedLongMatrix is multiple thread safe. The methods use lock-free atomic compare-and-set.
Note: Class SharedLongMatrix is implemented using class java.util.concurrent.atomic.AtomicLongArray.
| Constructor Summary | |
|---|---|
SharedLongMatrix(int rows,
int cols)
Construct a new long matrix reduction variable with the given number of rows and columns. |
|
SharedLongMatrix(long[][] matrix)
Construct a new long matrix reduction variable whose elements are copied from the given matrix. |
|
| Method Summary | |
|---|---|
long |
addAndGet(int r,
int c,
long value)
Add the given value to this matrix reduction variable at the given row and column and return the new value. |
int |
cols()
Returns the number of columns in this matrix reduction variable. |
boolean |
compareAndSet(int r,
int c,
long expect,
long update)
Atomically set this matrix reduction variable at the given row and column to the given updated value if the current value equals the expected value. |
long |
decrementAndGet(int r,
int c)
Subtract one from this matrix reduction variable at the given row and column and return the new value. |
long |
get(int r,
int c)
Returns this matrix reduction variable's current value at the given row and column. |
long |
getAndAdd(int r,
int c,
long value)
Add the given value to this matrix reduction variable at the given row and column and return the previous value. |
long |
getAndDecrement(int r,
int c)
Subtract one from this matrix reduction variable at the given row and column and return the previous value. |
long |
getAndIncrement(int r,
int c)
Add one to this matrix reduction variable at the given row and column and return the previous value. |
long |
getAndSet(int r,
int c,
long value)
Set this matrix reduction variable at the given row and column to the given value and return the previous value. |
long |
incrementAndGet(int r,
int c)
Add one to this matrix reduction variable at the given row and column and return the new value. |
void |
reduce(int dstrow,
int dstcol,
long[][] src,
int srcrow,
int srccol,
int rowlen,
int collen,
LongOp op)
Combine a portion of this matrix reduction variable with a portion of the given matrix using the given operation. |
long |
reduce(int r,
int c,
long value,
LongOp op)
Combine this matrix reduction variable at the given row and column with the given value using the given operation. |
void |
reduce(long[][] src,
LongOp op)
Combine this matrix reduction variable with the given matrix using the given operation. |
int |
rows()
Returns the number of rows in this matrix reduction variable. |
void |
set(int r,
int c,
long value)
Set this matrix reduction variable at the given row and column to the given value. |
boolean |
weakCompareAndSet(int r,
int c,
long expect,
long update)
Atomically set this matrix reduction variable at the given row and column to the given updated value if the current value equals the expected value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SharedLongMatrix(int rows,
int cols)
rows - Number of rows.cols - Number of columns.
NegativeArraySizeException - (unchecked exception) Thrown if rows < 0 or cols
< 0.public SharedLongMatrix(long[][] matrix)
matrix - Matrix to copy.
NullPointerException - (unchecked exception) Thrown if matrix is null or any row of
matrix is null.| Method Detail |
|---|
public int rows()
public int cols()
public long get(int r,
int c)
r - Row index.c - Column index.
public void set(int r,
int c,
long value)
r - Row index.c - Column index.value - New value.
public long getAndSet(int r,
int c,
long value)
r - Row index.c - Column index.value - New value.
public boolean compareAndSet(int r,
int c,
long expect,
long update)
r - Row index.c - Column index.expect - Expected value.update - Updated value.
public boolean weakCompareAndSet(int r,
int c,
long expect,
long update)
r - Row index.c - Column index.expect - Expected value.update - Updated value.
public long getAndIncrement(int r,
int c)
r - Row index.c - Column index.
public long getAndDecrement(int r,
int c)
r - Row index.c - Column index.
public long getAndAdd(int r,
int c,
long value)
r - Row index.c - Column index.value - Value to add.
public long incrementAndGet(int r,
int c)
r - Row index.c - Column index.
public long decrementAndGet(int r,
int c)
r - Row index.c - Column index.
public long addAndGet(int r,
int c,
long value)
r - Row index.c - Column index.value - Value to add.
public long reduce(int r,
int c,
long value,
LongOp op)
r - Row index.c - Column index.value - Value.op - Binary operation.
public void reduce(long[][] src,
LongOp op)
The reduce() method is multiple thread safe on a per-element basis. Each individual matrix element is updated atomically, but the matrix as a whole is not updated atomically.
src - Source matrix.op - Binary operation.
NullPointerException - (unchecked exception) Thrown if src is null. Thrown if
op is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if any matrix index would be out of
bounds.
public void reduce(int dstrow,
int dstcol,
long[][] src,
int srcrow,
int srccol,
int rowlen,
int collen,
LongOp op)
The reduce() method is multiple thread safe on a per-element basis. Each individual matrix element is updated atomically, but the matrix as a whole is not updated atomically.
dstrow - Row index of first element to update in this matrix.dstcol - Column index of first element to update in this matrix.src - Source matrix.srcrow - Row index of first element to update from in the source
matrix.srccol - Column index of first element to update from in the
source matrix.rowlen - Number of rows to update.collen - Number of columns to update.op - Binary operation.
NullPointerException - (unchecked exception) Thrown if src is null. Thrown if
op is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if rowlen < 0. Thrown if
collen < 0. Thrown if any matrix index would be out of
bounds.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||