Search in sources :

Example 11 with LongRange

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

the class WorkerLongStrideForLoop method masterExecuteFixed.

/**
 * Execute this worker for loop in the master thread with a fixed schedule.
 *
 * @param range Loop index range.
 * @param sch Schedule.
 *
 * @exception IOException Thrown if an I/O error occurred.
 */
void masterExecuteFixed(LongRange range, LongSchedule sch) throws IOException {
    int count = myTeam.count;
    Comm comm = myTeam.comm;
    // Send additional task input to each worker.
    sch.start(count, range);
    for (int w = 0; w < count; ++w) {
        LongRange chunk = sch.next(w);
        if (chunk != null) {
            sendTaskInput(chunk, comm, myTeam.workerRank(w), tagFor(w));
        }
    }
    // Receive additional task output from each worker.
    sch.start(count, range);
    for (int w = 0; w < count; ++w) {
        LongRange chunk = sch.next(w);
        if (chunk != null) {
            receiveTaskOutput(chunk, comm, myTeam.workerRank(w), tagFor(w));
        }
    }
}
Also used : LongRange(edu.rit.util.LongRange)

Example 12 with LongRange

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

the class WorkerLongStrideForLoop 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 13 with LongRange

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

the class WorkerLongStrideForLoop 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<LongRange> buf = ObjectBuf.buffer();
    for (; ; ) {
        comm.receive(r, tag, buf);
        LongRange range = buf.item;
        if (range == null) {
            break;
        }
        receiveTaskInput(range, comm, r, tag);
        run(range.lb(), range.ub(), range.stride());
        // messages, or the master can deadlock.
        synchronized (myTeam) {
            comm.send(r, tag, buf);
            sendTaskOutput(range, comm, r, tag);
        }
    }
    finish();
}
Also used : LongRange(edu.rit.util.LongRange)

Aggregations

LongRange (edu.rit.util.LongRange)13 Range (edu.rit.util.Range)2