Search in sources :

Example 41 with Range

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

the class WorkerLongForLoop method masterExecuteNonFixed.

/**
 * Execute this worker for loop in the master thread with a non-fixed
 * schedule.
 *
 * @param range Loop index range.
 * @param sch Schedule.
 *
 * @exception IOException Thrown if an I/O error occurred.
 */
void masterExecuteNonFixed(LongRange range, LongSchedule sch) throws IOException {
    int count = myTeam.count;
    sch.start(count, range);
    int remaining = count;
    ObjectItemBuf<LongRange> buf = ObjectBuf.buffer();
    Range tagRange = new Range(tagFor(0), tagFor(count - 1));
    Comm comm = myTeam.comm;
    // Send initial task to each worker.
    for (int w = 0; w < count; ++w) {
        LongRange chunk = sch.next(w);
        buf.item = chunk;
        buf.reset();
        int r = myTeam.workerRank(w);
        int tag = tagFor(w);
        comm.send(r, tag, buf);
        if (chunk == null) {
            --remaining;
        } else {
            sendTaskInput(chunk, comm, r, tag);
        }
    }
    // that worker.
    while (remaining > 0) {
        CommStatus status = comm.receive(null, tagRange, buf);
        LongRange chunk = buf.item;
        int r = status.fromRank;
        int tag = status.tag;
        int w = workerFor(tag);
        receiveTaskOutput(chunk, comm, r, tag);
        chunk = sch.next(w);
        buf.item = chunk;
        buf.reset();
        comm.send(r, tag, buf);
        if (chunk == null) {
            --remaining;
        } else {
            sendTaskInput(chunk, comm, r, tag);
        }
    }
}
Also used : LongRange(edu.rit.util.LongRange) Range(edu.rit.util.Range) LongRange(edu.rit.util.LongRange)

Example 42 with Range

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

the class WorkerRegion method execute.

/**
 * Execute a worker for loop within this worker region. For further
 * information, see class {@linkplain WorkerIntegerForLoop}. The loop index
 * goes from <TT>first</TT> (inclusive) to <TT>last</TT> (inclusive) in
 * steps of +1. If <TT>first</TT> is greater than <TT>last</TT>, then no
 * loop iterations are performed.
 * <P>
 * <I>Note:</I> Either all threads in the worker team must call the
 * <TT>execute()</TT> method with identical arguments, or none of the
 * threads must call the <TT>execute()</TT> method.
 *
 * @param first First loop index.
 * @param last Last loop index.
 * @param theLoop Worker for loop.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theLoop</TT> is null.
 * @exception IllegalStateException (unchecked exception) Thrown if no
 * worker team is executing this worker region.
 * @exception Exception Thrown if one of <TT>theLoop</TT>'s methods throws
 * an exception.
 * @throws java.lang.Exception if any.
 */
public final void execute(int first, int last, WorkerIntegerForLoop theLoop) throws Exception {
    // Verify preconditions.
    if (theLoop == null) {
        throw new NullPointerException("WorkerRegion.execute(): Worker for loop is null");
    }
    if (myTeam == null) {
        throw new IllegalStateException("WorkerRegion.execute(): No parallel team executing");
    }
    try {
        // Record parallel team.
        theLoop.myTeam = this.myTeam;
        // Get current parallel team thread.
        WorkerTeamThread currentThread = getCurrentThread();
        int w = currentThread.myIndex;
        // Do master or worker thread processing.
        Range range = new Range(first, last);
        if (w == -1) {
            theLoop.masterExecute(range);
        } else {
            theLoop.workerExecute(w, range);
        }
    } finally {
        // Forget parallel team.
        theLoop.myTeam = null;
    }
}
Also used : Range(edu.rit.util.Range) LongRange(edu.rit.util.LongRange)

Example 43 with Range

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

the class WorkerRegion method execute.

/**
 * Execute a worker for loop within this worker region. For further
 * information, see class {@linkplain WorkerIntegerStrideForLoop}. The loop
 * index goes from <TT>first</TT> (inclusive) to <TT>last</TT> (inclusive)
 * in steps of <TT>stride</TT>. The stride must be positive. If
 * <TT>first</TT> is greater than <TT>last</TT>, then no loop iterations are
 * performed.
 * <P>
 * <I>Note:</I> Either all threads in the worker team must call the
 * <TT>execute()</TT> method with identical arguments, or none of the
 * threads must call the <TT>execute()</TT> method.
 *
 * @param first First loop index.
 * @param last Last loop index.
 * @param stride Loop index stride, &gt;= 1.
 * @param theLoop Worker for loop.
 * @exception IllegalArgumentException (unchecked exception) Thrown if
 * <TT>stride</TT> &lt; 1.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theLoop</TT> is null.
 * @exception IllegalStateException (unchecked exception) Thrown if no
 * worker team is executing this worker region.
 * @exception Exception Thrown if one of <TT>theLoop</TT>'s methods throws
 * an exception.
 * @throws java.lang.Exception if any.
 */
public final void execute(int first, int last, int stride, WorkerIntegerStrideForLoop theLoop) throws Exception {
    // Verify preconditions.
    if (stride <= 0) {
        throw new IllegalArgumentException("WorkerRegion.execute(): Stride = " + stride + " illegal");
    }
    if (theLoop == null) {
        throw new NullPointerException("WorkerRegion.execute(): Worker for loop is null");
    }
    if (myTeam == null) {
        throw new IllegalStateException("WorkerRegion.execute(): No parallel team executing");
    }
    try {
        // Record parallel team.
        theLoop.myTeam = this.myTeam;
        // Get current parallel team thread.
        WorkerTeamThread currentThread = getCurrentThread();
        int w = currentThread.myIndex;
        // Do master or worker thread processing.
        Range range = new Range(first, last, stride);
        if (w == -1) {
            theLoop.masterExecute(range);
        } else {
            theLoop.workerExecute(w, range);
        }
    } finally {
        // Forget parallel team.
        theLoop.myTeam = null;
    }
}
Also used : Range(edu.rit.util.Range) LongRange(edu.rit.util.LongRange)

Example 44 with Range

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

the class PairwiseSchedule method updateRanges.

/**
 * <p>
 * updateRanges</p>
 *
 * @param totalInteractions a int.
 * @param atomsWithInteractions the number of chunks of interactions.
 * @param listCount an array of int.
 */
public void updateRanges(int totalInteractions, int atomsWithInteractions, int[] listCount) {
    int id = 0;
    int goal = totalInteractions / (nThreads + threadOffset);
    int num = 0;
    int start = 0;
    for (int i = 0; i < nAtoms; i++) {
        num += listCount[i];
        if (num >= goal) {
            /**
             * Last thread gets the remaining atoms.
             */
            if (id == nThreads - 1) {
                ranges[id] = new Range(start, nAtoms - 1);
                break;
            }
            ranges[id] = new Range(start, i);
            // Zero out the interaction counter.
            num = 0;
            // Next thread.
            id++;
            // Next range starts at i+1.
            start = i + 1;
            /**
             * Out of atoms. Threads remaining get a null range.
             */
            if (start == nAtoms) {
                if (atomsWithInteractions > nThreads + threadOffset + 1) {
                    threadOffset++;
                    updateRanges(totalInteractions, atomsWithInteractions, listCount);
                    break;
                }
                for (int j = id; j < nThreads; j++) {
                    ranges[j] = null;
                }
                break;
            }
        } else if (i == nAtoms - 1) {
            /**
             * Last atom without reaching goal for current thread.
             */
            if (id < nThreads - 1 && atomsWithInteractions > nThreads + threadOffset + 1) {
                threadOffset++;
                updateRanges(totalInteractions, atomsWithInteractions, listCount);
                break;
            }
            ranges[id] = new Range(start, nAtoms - 1);
            for (int j = id + 1; j < nThreads; j++) {
                ranges[j] = null;
            }
        }
    }
    threadOffset = 0;
}
Also used : Range(edu.rit.util.Range)

Example 45 with Range

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

the class ObjectBuf method buffer.

/**
 * Create a buffer for the entire given object matrix. The returned buffer
 * encompasses all the rows and all the columns in
 * <TT>theMatrix</TT>. The matrix elements are sent and received as multiple
 * separate objects of type <TT>T</TT>.
 *
 * @param <T> Data type of the objects in the buffer.
 * @param theMatrix Matrix.
 * @return Buffer.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theMatrix</TT> is null.
 */
public static <T> ObjectBuf<T> buffer(T[][] theMatrix) {
    if (theMatrix == null) {
        throw new NullPointerException("ObjectBuf.buffer(): theMatrix is null");
    }
    int nr = Arrays.rowLength(theMatrix);
    int nc = Arrays.colLength(theMatrix, 0);
    return new ObjectMatrixBuf_1<T>(theMatrix, new Range(0, nr - 1), new Range(0, nc - 1));
}
Also used : ObjectMatrixBuf_1(edu.rit.mp.buf.ObjectMatrixBuf_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