Class Unsigned16BitIntegerBuf
- Direct Known Subclasses:
EmptyUnsigned16BitIntegerBuf
,SharedUnsigned16BitIntegerArrayBuf
,SharedUnsigned16BitIntegerBuf
,Unsigned16BitIntegerArrayBuf
,Unsigned16BitIntegerItemBuf
,Unsigned16BitIntegerMatrixBuf
A buffer may be used to send one or more messages at the same time in multiple threads. If a buffer is being used to send a message or messages, the buffer must not be used to receive a message at the same time.
A buffer may be used to receive one message at a time. If a buffer is being used to receive a message, the buffer must not be used to receive another message in a different thread, and the buffer must not be used to send a message or messages.
A buffer is a conduit for retrieving and storing data in some underlying data structure. If the underlying data structure is multiple thread safe, then one thread can be retrieving or storing data via the buffer at the same time as other threads are accessing the data structure. If the underlying data structure is not multiple thread safe, then other threads must not access the data structure while one thread is retrieving or storing data via the buffer.
To create an Unsigned16BitIntegerBuf, call one of the following static factory methods:
emptyBuffer()
buffer()
buffer (int)
buffer (int[])
sliceBuffer (int[], Range)
sliceBuffers (int[], Range[])
buffer (int[][])
rowSliceBuffer (int[][], Range)
rowSliceBuffers (int[][], Range[])
colSliceBuffer (int[][], Range)
colSliceBuffers (int[][], Range[])
patchBuffer (int[][], Range, Range)
patchBuffers (int[][], Range[], Range[])
buffer (SharedInteger)
buffer (SharedIntegerArray)
sliceBuffer (SharedIntegerArray, Range)
sliceBuffers (SharedIntegerArray, Range[])
- Version:
- 03-May-2008
- Author:
- Alan Kaminsky
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Unsigned16BitIntegerBuf
(int theLength) Construct a new unsigned 16-bit integer buffer. -
Method Summary
Modifier and TypeMethodDescriptionstatic Unsigned16BitIntegerItemBuf
buffer()
Create a buffer for an integer item.static Unsigned16BitIntegerItemBuf
buffer
(int item) Create a buffer for an integer item with the given initial value.static Unsigned16BitIntegerBuf
buffer
(int[] theArray) Create a buffer for the entire given integer array.static Unsigned16BitIntegerBuf
buffer
(int[][] theMatrix) Create a buffer for the entire given integer matrix.static Unsigned16BitIntegerBuf
buffer
(SharedInteger item) Create a buffer for a shared integer item.static Unsigned16BitIntegerBuf
buffer
(SharedIntegerArray theArray) Create a buffer for the entire given shared integer array.static Unsigned16BitIntegerBuf
colSliceBuffer
(int[][] theMatrix, Range theColRange) Create a buffer for one column slice of the given integer matrix.static Unsigned16BitIntegerBuf[]
colSliceBuffers
(int[][] theMatrix, Range[] theColRanges) Create an array of buffers for multiple column slices of the given integer matrix.void
Copy items from the given buffer to this buffer.protected static void
defaultCopy
(Unsigned16BitIntegerBuf theSrc, Unsigned16BitIntegerBuf theDst) Copy items from the given source buffer to the given destination buffer.static Unsigned16BitIntegerBuf
Create an empty buffer.void
Fill this buffer with the given item.abstract int
get
(int i) Obtain the given item from this buffer.Create a temporary buffer with the same type of items and the same length as this buffer.static Unsigned16BitIntegerBuf
patchBuffer
(int[][] theMatrix, Range theRowRange, Range theColRange) Create a buffer for one patch of the given integer matrix.static Unsigned16BitIntegerBuf[]
patchBuffers
(int[][] theMatrix, Range[] theRowRanges, Range[] theColRanges) Create an array of buffers for multiple patches of the given integer matrix.abstract void
put
(int i, int item) Store the given item in this buffer.static Unsigned16BitIntegerBuf
rowSliceBuffer
(int[][] theMatrix, Range theRowRange) Create a buffer for one row slice of the given integer matrix.static Unsigned16BitIntegerBuf[]
rowSliceBuffers
(int[][] theMatrix, Range[] theRowRanges) Create an array of buffers for multiple row slices of the given integer matrix.static Unsigned16BitIntegerBuf
sliceBuffer
(int[] theArray, Range theRange) Create a buffer for one slice of the given integer array.static Unsigned16BitIntegerBuf
sliceBuffer
(SharedIntegerArray theArray, Range theRange) Create a buffer for one slice of the given shared integer array.static Unsigned16BitIntegerBuf[]
sliceBuffers
(int[] theArray, Range[] theRanges) Create an array of buffers for multiple slices of the given integer array.static Unsigned16BitIntegerBuf[]
sliceBuffers
(SharedIntegerArray theArray, Range[] theRanges) Create an array of buffers for multiple slices of the given shared integer array.Methods inherited from class edu.rit.mp.Buf
getReductionBuf, length, receiveItems, sendItems
-
Constructor Details
-
Unsigned16BitIntegerBuf
protected Unsigned16BitIntegerBuf(int theLength) Construct a new unsigned 16-bit integer buffer.- Parameters:
theLength
- Number of items.- Throws:
IllegalArgumentException
- (unchecked exception) Thrown iftheLength
< 0.
-
-
Method Details
-
emptyBuffer
Create an empty buffer. The buffer's length is 0. The buffer's item type is unsigned 16-bit integer.- Returns:
- Empty buffer.
-
buffer
Create a buffer for an integer item. The item is stored in theitem
field of the buffer.- Returns:
- Buffer.
-
buffer
Create a buffer for an integer item with the given initial value. The item is stored in theitem
field of the buffer.- Parameters:
item
- Initial value of theitem
field.- Returns:
- Buffer.
-
buffer
Create a buffer for the entire given integer array. The returned buffer encompasses all the elements intheArray
.- Parameters:
theArray
- Array.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheArray
is null.
-
sliceBuffer
Create a buffer for one slice of the given integer array. The returned buffer encompassestheRange
of elements intheArray
. The range's stride may be 1 or greater than 1.- Parameters:
theArray
- Array.theRange
- Range of elements to include.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheArray
is null ortheRange
is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheArray
does not include all the indexes intheRange
.
-
sliceBuffers
Create an array of buffers for multiple slices of the given integer array. The returned buffer array has the same length astheRanges
. Each element [i] of the returned buffer array encompasses the elements oftheArray
specified bytheRanges[i]
. Each range's stride may be 1 or greater than 1.- Parameters:
theArray
- Array.theRanges
- Array of ranges of elements to include.- Returns:
- Array of buffers.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheArray
is null ortheRanges
or any element thereof is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheArray
's allocation does not include any element oftheRanges
.
-
buffer
Create a buffer for the entire given integer matrix. The returned buffer encompasses all the rows and all the columns intheMatrix
.- Parameters:
theMatrix
- Matrix.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null.
-
rowSliceBuffer
Create a buffer for one row slice of the given integer matrix. The returned buffer encompassestheRowRange
of rows, and all the columns, intheMatrix
. The range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theRowRange
- Range of rows to include.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null ortheRowRange
is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not includetheRowRange
.
-
rowSliceBuffers
Create an array of buffers for multiple row slices of the given integer matrix. The returned buffer array has the same length astheRowRanges
. Each element [i] of the returned buffer array encompasses the rows oftheMatrix
specified bytheRowRanges[i]
and all the columns oftheMatrix
. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theRowRanges
- Array of ranges of rows to include.- Returns:
- Array of buffers.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null ortheRowRanges
or any element thereof is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not include any element oftheRowRanges
.
-
colSliceBuffer
Create a buffer for one column slice of the given integer matrix. The returned buffer encompasses all the rows, andtheColRange
of columns, intheMatrix
. The range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theColRange
- Range of columns to include.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null ortheColRange
is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not includetheColRange
.
-
colSliceBuffers
Create an array of buffers for multiple column slices of the given integer matrix. The returned buffer array has the same length astheColRanges
. Each element [i] of the returned buffer array encompasses all the rows oftheMatrix
and the columns oftheMatrix
specified bytheColRanges[i]
. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theColRanges
- Array of ranges of columns to include.- Returns:
- Array of buffers.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null ortheColRanges
or any element thereof is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not include any element oftheColRanges
.
-
patchBuffer
public static Unsigned16BitIntegerBuf patchBuffer(int[][] theMatrix, Range theRowRange, Range theColRange) Create a buffer for one patch of the given integer matrix. The returned buffer encompassestheRowRange
of rows, andtheColRange
of columns, intheMatrix
. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theRowRange
- Range of rows to include.theColRange
- Range of columns to include.- Returns:
- Buffer.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null,theRowRange
is null, ortheColRange
is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not includetheRowRange
andtheColRange
.
-
patchBuffers
public static Unsigned16BitIntegerBuf[] patchBuffers(int[][] theMatrix, Range[] theRowRanges, Range[] theColRanges) Create an array of buffers for multiple patches of the given integer matrix. The length of the returned buffer array is equal to the length oftheRowRanges
times the length oftheColRanges
. Each element of the returned buffer array encompasses the rows given in one element oftheRowRanges
array, and the columns given in one element oftheColRanges
array, in all possible combinations, oftheMatrix
. Each range's stride may be 1 or greater than 1.- Parameters:
theMatrix
- Matrix.theRowRanges
- Array of ranges of rows to include.theColRanges
- Array of ranges of columns to include.- Returns:
- Array of buffers.
- Throws:
NullPointerException
- (unchecked exception) Thrown iftheMatrix
is null,theRowRanges
or any element thereof is null, ortheColRanges
or any element thereof is null.IndexOutOfBoundsException
- (unchecked exception) Thrown iftheMatrix
's allocation does not include any element oftheRowRanges
ortheColRanges
.
-
get
public abstract int get(int i) Obtain the given item from this buffer.The
get()
method must not block the calling thread; if it does, all message I/O in MP will be blocked.- Parameters:
i
- Item index in the range 0 ..length()
-1.- Returns:
- Item at index
i
.
-
put
public abstract void put(int i, int item) Store the given item in this buffer.The
put()
method must not block the calling thread; if it does, all message I/O in MP will be blocked.- Parameters:
i
- Item index in the range 0 ..length()
-1.item
- Item to be stored at indexi
.
-
copy
Copy items from the given buffer to this buffer. The number of items copied is this buffer's length ortheSrc
's length, whichever is smaller. IftheSrc
is this buffer, thecopy()
method does nothing. Copy items from the given buffer to this buffer. The number of items copied is this buffer's length ortheSrc
's length, whichever is smaller. IftheSrc
is this buffer, thecopy()
method does nothing.The default implementation of the
copy()
method calls thedefaultCopy()
method. A subclass can override thecopy()
method to use a more efficient algorithm.- Specified by:
copy
in classBuf
- Parameters:
theSrc
- Source of items to copy into this buffer.- Throws:
ClassCastException
- (unchecked exception) Thrown iftheSrc
's item data type is not the same as this buffer's item data type.
-
fill
Fill this buffer with the given item. Theitem
is assigned to each element in this buffer.If this buffer's item data type is a primitive type, the
item
must be an instance of the corresponding primitive wrapper class -- class Integer for typeint
, class Double for typedouble
, and so on. If theitem
is null, the item data type's default initial value is assigned to each element in this buffer.If this buffer's item data type is a nonprimitive type, the
item
must be an instance of the item class or a subclass thereof. Theitem
may be null. Note that sinceitem
is assigned to every buffer element, every buffer element ends up referring to the sameitem
. Fill this buffer with the given item. Theitem
is assigned to each element in this buffer.The
item
must be an instance of class Integer. If theitem
is null, 0 is assigned to each element in this buffer.- Specified by:
fill
in classBuf
- Parameters:
item
- Item.- Throws:
ClassCastException
- (unchecked exception) Thrown if theitem
's data type is not the same as this buffer's item data type.
-
getTemporaryBuf
Create a temporary buffer with the same type of items and the same length as this buffer. The new buffer items are stored in a newly created array, separate from the storage for this buffer's items.- Specified by:
getTemporaryBuf
in classBuf
- Returns:
- a
Buf
object.
-
defaultCopy
Copy items from the given source buffer to the given destination buffer. The number of items copied istheSrc
's length ortheDst
's length, whichever is smaller. Each item is copied individually using theget()
andput()
methods. It is assumed thattheSrc
is not the same astheDst
.- Parameters:
theSrc
- Source of items to copy.theDst
- Destination of items to copy.
-