Search in sources :

Example 1 with Range

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;
    }
}
Also used : Range(edu.rit.util.Range)

Example 2 with Range

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;
    }
}
Also used : Range(edu.rit.util.Range)

Example 3 with Range

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));
}
Also used : CharacterMatrixBuf_1(edu.rit.mp.buf.CharacterMatrixBuf_1) Range(edu.rit.util.Range)

Example 4 with Range

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));
}
Also used : FloatMatrixBuf_1(edu.rit.mp.buf.FloatMatrixBuf_1) Range(edu.rit.util.Range)

Example 5 with Range

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));
    }
}
Also used : FloatMatrixBuf(edu.rit.mp.buf.FloatMatrixBuf) FloatMatrixBuf_1(edu.rit.mp.buf.FloatMatrixBuf_1) Range(edu.rit.util.Range)

Aggregations

Range (edu.rit.util.Range)76 LongRange (edu.rit.util.LongRange)6 BooleanMatrixBuf_1 (edu.rit.mp.buf.BooleanMatrixBuf_1)3 ByteMatrixBuf_1 (edu.rit.mp.buf.ByteMatrixBuf_1)3 CharacterMatrixBuf_1 (edu.rit.mp.buf.CharacterMatrixBuf_1)3 DoubleMatrixBuf_1 (edu.rit.mp.buf.DoubleMatrixBuf_1)3 FloatMatrixBuf_1 (edu.rit.mp.buf.FloatMatrixBuf_1)3 IntegerMatrixBuf_1 (edu.rit.mp.buf.IntegerMatrixBuf_1)3 LongMatrixBuf_1 (edu.rit.mp.buf.LongMatrixBuf_1)3 ObjectMatrixBuf_1 (edu.rit.mp.buf.ObjectMatrixBuf_1)3 ShortMatrixBuf_1 (edu.rit.mp.buf.ShortMatrixBuf_1)3 Signed16BitIntegerMatrixBuf_1 (edu.rit.mp.buf.Signed16BitIntegerMatrixBuf_1)3 Signed8BitIntegerMatrixBuf_1 (edu.rit.mp.buf.Signed8BitIntegerMatrixBuf_1)3 Unsigned16BitIntegerMatrixBuf_1 (edu.rit.mp.buf.Unsigned16BitIntegerMatrixBuf_1)3 Unsigned8BitIntegerMatrixBuf_1 (edu.rit.mp.buf.Unsigned8BitIntegerMatrixBuf_1)3 BooleanMatrixBuf (edu.rit.mp.buf.BooleanMatrixBuf)2 ByteMatrixBuf (edu.rit.mp.buf.ByteMatrixBuf)2 CharacterMatrixBuf (edu.rit.mp.buf.CharacterMatrixBuf)2 DoubleMatrixBuf (edu.rit.mp.buf.DoubleMatrixBuf)2 FloatMatrixBuf (edu.rit.mp.buf.FloatMatrixBuf)2