use of edu.rit.util.Range in project ffx by mjschnie.
the class RowSchedule method defineRanges.
private void defineRanges() {
double totalWeight = totalWeight();
/**
* Infrequent edge case where the total weight is less than or equal to
* the number of threads.
*/
if (totalWeight <= nThreads) {
Range temp = new Range(0, fftZ * fftY - 1);
ranges = temp.subranges(nThreads);
return;
}
/**
* Handle the case where we only have a single thread, which will
* receive all the rows.
*/
if (nThreads == 1) {
ranges[0] = new Range(0, fftZ * fftY - 1);
return;
}
double targetWeight = (totalWeight / nThreads);
int lastRow = fftZ * fftY - 1;
int currentRow = 0;
lowerBounds[0] = 0;
int currentThread = 0;
while (currentThread < nThreads) {
int threadWeight = 0;
while (threadWeight < targetWeight && currentRow < lastRow) {
threadWeight += weights[currentRow];
currentRow++;
}
currentThread++;
if (currentRow < lastRow) {
lowerBounds[currentThread] = currentRow;
} else {
lowerBounds[currentThread] = lastRow;
break;
}
}
int lastThread = currentThread;
/**
* Loop over all threads that will receive work except the final one.
*/
for (currentThread = 0; currentThread < lastThread - 1; currentThread++) {
ranges[currentThread] = new Range(lowerBounds[currentThread], lowerBounds[currentThread + 1] - 1);
// logger.info(String.format("Range for thread %d %s.", currentThread, ranges[currentThread]));
}
/**
* Final range for the last thread that will receive work.
*/
ranges[lastThread - 1] = new Range(lowerBounds[lastThread - 1], lastRow);
/**
* Left-over threads with null ranges.
*/
for (int it = lastThread; it < nThreads; it++) {
ranges[it] = null;
}
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class SliceSchedule method defineRanges.
private void defineRanges() {
double totalWeight = totalWeight();
/**
* Infrequent edge case where the total weight is less than or equal to
* the number of threads.
*/
if (totalWeight <= nThreads) {
Range temp = new Range(0, fftZ - 1);
ranges = temp.subranges(nThreads);
return;
}
/**
* Handle the case where we only have a single thread, which will
* receive all the slices.
*/
if (nThreads == 1) {
ranges[0] = new Range(0, fftZ - 1);
return;
}
double targetWeight = (totalWeight / nThreads) * .96;
int lastSlice = fftZ - 1;
int currentSlice = 0;
lowerBounds[0] = 0;
int currentThread = 0;
while (currentThread < nThreads) {
int threadWeight = 0;
while (threadWeight < targetWeight && currentSlice < lastSlice) {
threadWeight += weights[currentSlice];
currentSlice++;
}
currentThread++;
if (currentSlice < lastSlice) {
lowerBounds[currentThread] = currentSlice;
} else {
lowerBounds[currentThread] = lastSlice;
break;
}
}
int lastThread = currentThread;
/**
* Loop over all threads that will receive work except the final one.
*/
for (currentThread = 0; currentThread < lastThread - 1; currentThread++) {
ranges[currentThread] = new Range(lowerBounds[currentThread], lowerBounds[currentThread + 1] - 1);
// logger.info(String.format("Range for thread %d %s.", currentThread, ranges[currentThread]));
}
/**
* Final range for the last thread that will receive work.
*/
ranges[lastThread - 1] = new Range(lowerBounds[lastThread - 1], lastSlice);
/**
* Left-over threads with null ranges.
*/
for (int it = lastThread; it < nThreads; it++) {
ranges[it] = null;
}
}
use of edu.rit.util.Range in project ffx by mjschnie.
the class CharacterBuf method buffer.
/**
* Create a buffer for the entire given character 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 CharacterBuf buffer(char[][] theMatrix) {
if (theMatrix == null) {
throw new NullPointerException("CharacterBuf.buffer(): theMatrix is null");
}
int nr = Arrays.rowLength(theMatrix);
int nc = Arrays.colLength(theMatrix, 0);
return new CharacterMatrixBuf_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 FloatBuf method buffer.
/**
* Create a buffer for the entire given float 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 FloatBuf buffer(float[][] theMatrix) {
if (theMatrix == null) {
throw new NullPointerException("FloatBuf.buffer(): theMatrix is null");
}
int nr = Arrays.rowLength(theMatrix);
int nc = Arrays.colLength(theMatrix, 0);
return new FloatMatrixBuf_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 FloatBuf method rowSliceBuffer.
/**
* Create a buffer for one row slice of the given float matrix. The returned
* buffer encompasses <TT>theRowRange</TT> of rows, and all the columns, in
* <TT>theMatrix</TT>. The range's stride may be 1 or greater than 1.
*
* @param theMatrix Matrix.
* @param theRowRange Range of rows to include.
* @return Buffer.
* @exception NullPointerException (unchecked exception) Thrown if
* <TT>theMatrix</TT> is null or
* <TT>theRowRange</TT> is null.
* @exception IndexOutOfBoundsException (unchecked exception) Thrown if
* <TT>theMatrix</TT>'s allocation does not include <TT>theRowRange</TT>.
*/
public static FloatBuf rowSliceBuffer(float[][] theMatrix, Range theRowRange) {
if (theMatrix == null) {
throw new NullPointerException("FloatBuf.rowSliceBuffer(): theMatrix is null");
}
int nr = Arrays.rowLength(theMatrix);
if (0 > theRowRange.lb() || theRowRange.ub() >= nr) {
throw new IndexOutOfBoundsException("FloatBuf.rowSliceBuffer(): theMatrix row index range = 0.." + (nr - 1) + ", theRowRange = " + theRowRange);
}
int nc = Arrays.colLength(theMatrix, theRowRange.lb());
if (theRowRange.stride() == 1) {
return new FloatMatrixBuf_1(theMatrix, theRowRange, new Range(0, nc - 1));
} else {
return new FloatMatrixBuf(theMatrix, theRowRange, new Range(0, nc - 1));
}
}
Aggregations