use of edu.rit.util.Range in project ffx by mjschnie.
the class IntegerBuf method colSliceBuffer.
/**
* Create a buffer for one column slice of the given integer matrix. The
* returned buffer encompasses all the rows, and <TT>theColRange</TT> of
* columns, in <TT>theMatrix</TT>. The range's stride may be 1 or greater
* than 1.
*
* @param theMatrix Matrix.
* @param theColRange Range of columns to include.
* @return Buffer.
* @exception NullPointerException (unchecked exception) Thrown if
* <TT>theMatrix</TT> is null or
* <TT>theColRange</TT> is null.
* @exception IndexOutOfBoundsException (unchecked exception) Thrown if
* <TT>theMatrix</TT>'s allocation does not include <TT>theColRange</TT>.
*/
public static IntegerBuf colSliceBuffer(int[][] theMatrix, Range theColRange) {
if (theMatrix == null) {
throw new NullPointerException("IntegerBuf.colSliceBuffer(): theMatrix is null");
}
int nr = Arrays.rowLength(theMatrix);
int nc = Arrays.colLength(theMatrix, 0);
if (0 > theColRange.lb() || theColRange.ub() >= nc) {
throw new IndexOutOfBoundsException("IntegerBuf.colSliceBuffer(): theMatrix column index range = 0.." + (nc - 1) + ", theColRange = " + theColRange);
}
if (theColRange.stride() == 1) {
return new IntegerMatrixBuf_1(theMatrix, new Range(0, nr - 1), theColRange);
} else {
return new IntegerMatrixBuf(theMatrix, new Range(0, nr - 1), theColRange);
}
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class IntegerBuf method buffer.
/**
* Create a buffer for the entire given integer matrix. The returned buffer
* encompasses all the rows and all the columns in
* <TT>theMatrix</TT>.
*
* @param theMatrix Matrix.
* @return Buffer.
* @exception NullPointerException (unchecked exception) Thrown if
* <TT>theMatrix</TT> is null.
*/
public static IntegerBuf buffer(int[][] theMatrix) {
if (theMatrix == null) {
throw new NullPointerException("IntegerBuf.buffer(): theMatrix is null");
}
int nr = Arrays.rowLength(theMatrix);
int nc = Arrays.colLength(theMatrix, 0);
return new IntegerMatrixBuf_1(theMatrix, new Range(0, nr - 1), new Range(0, nc - 1));
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class Unsigned16BitIntegerBuf method patchBuffers.
/**
* 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 of
* <TT>theRowRanges</TT> times the length of <TT>theColRanges</TT>. Each
* element of the returned buffer array encompasses the rows given in one
* element of <TT>theRowRanges</TT> array, and the columns given in one
* element of <TT>theColRanges</TT> array, in all possible combinations, of
* <TT>theMatrix</TT>. Each range's stride may be 1 or greater than 1.
*
* @param theMatrix Matrix.
* @param theRowRanges Array of ranges of rows to include.
* @param theColRanges Array of ranges of columns to include.
* @return Array of buffers.
* @exception NullPointerException (unchecked exception) Thrown if
* <TT>theMatrix</TT> is null,
* <TT>theRowRanges</TT> or any element thereof is null, or
* <TT>theColRanges</TT> or any element thereof is null.
* @exception IndexOutOfBoundsException (unchecked exception) Thrown if
* <TT>theMatrix</TT>'s allocation does not include any element of
* <TT>theRowRanges</TT> or
* <TT>theColRanges</TT>.
*/
public static Unsigned16BitIntegerBuf[] patchBuffers(int[][] theMatrix, Range[] theRowRanges, Range[] theColRanges) {
int m = theRowRanges.length;
int n = theColRanges.length;
Unsigned16BitIntegerBuf[] result = new Unsigned16BitIntegerBuf[m * n];
int k = 0;
for (int i = 0; i < m; ++i) {
Range rowrange = theRowRanges[i];
for (int j = 0; j < n; ++j) {
result[k++] = patchBuffer(theMatrix, rowrange, theColRanges[j]);
}
}
return result;
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class WorkerIntegerForLoop method workerExecuteNonFixed.
/**
* Execute this worker for loop in a worker thread using a non-fixed
* schedule.
*
* @param w Worker index.
*
* @exception Exception This method may throw any exception.
*/
void workerExecuteNonFixed(int w) throws Exception {
Comm comm = myTeam.comm;
int r = myTeam.masterRank();
int tag = tagFor(w);
start();
ObjectItemBuf<Range> buf = ObjectBuf.buffer();
for (; ; ) {
comm.receive(r, tag, buf);
Range range = buf.item;
if (range == null) {
break;
}
receiveTaskInput(range, comm, r, tag);
run(range.lb(), range.ub());
// messages, or the master can deadlock.
synchronized (myTeam) {
comm.send(r, tag, buf);
sendTaskOutput(range, comm, r, tag);
}
}
finish();
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class DynamicIntegerSchedule method next.
/**
* {@inheritDoc}
*
* Obtain the next chunk of iterations for the given thread index. If there
* are more iterations, a range object is returned whose lower bound, upper
* bound, and stride specify the chunk of iterations to perform. The
* returned range object's stride is the same as that given to the
* <TT>start()</TT> method. The returned range object's lower bound and
* upper bound are contained within the range given to the <TT>start()</TT>
* method. If there are no more iterations, null is returned.
* <P>
* The <TT>next()</TT> method is called by multiple parallel team threads in
* the Parallel Java middleware. The <TT>next()</TT> method must be multiple
* thread safe.
*/
public Range next(int theThreadIndex) {
for (; ; ) {
int oldN1 = N1.get();
Range result = myLoopRange.chunk(oldN1, N2);
int N = result.length();
if (N == 0) {
return null;
}
int newN1 = oldN1 + N;
if (N1.compareAndSet(oldN1, newN1)) {
return result;
}
}
}
Aggregations