Search in sources :

Example 76 with Range

use of edu.rit.util.Range in project ffx by mjschnie.

the class GradientSchedule 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, nAtoms - 1);
        ranges = temp.subranges(nThreads);
        return;
    }
    /**
     * Handle the case where we only have a single thread, which will
     * receive all the atoms.
     */
    if (nThreads == 1) {
        ranges[0] = new Range(0, nAtoms - 1);
        return;
    }
    double targetWeight = (totalWeight / nThreads);
    int lastAtom = nAtoms - 1;
    int currentAtom = 0;
    lowerBounds[0] = 0;
    int currentThread = 0;
    while (currentThread < nThreads) {
        int threadWeight = 0;
        while (threadWeight < targetWeight && currentAtom < lastAtom) {
            threadWeight += weights[currentAtom];
            currentAtom++;
        }
        currentThread++;
        if (currentAtom < lastAtom) {
            lowerBounds[currentThread] = currentAtom;
        } else {
            lowerBounds[currentThread] = lastAtom;
            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], lastAtom);
    /**
     * Left-over threads with null ranges.
     */
    for (int it = lastThread; it < nThreads; it++) {
        ranges[it] = null;
    }
}
Also used : 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