Search in sources :

Example 36 with Range

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

the class WorkerIteration method masterExecute.

// Hidden operations.
/**
 * Execute this worker iteration in the master thread.
 *
 * @param generator Item generator.
 *
 * @exception IOException Thrown if an I/O error occurred.
 */
void masterExecute(ItemGenerator<T> generator) throws IOException {
    int count = myTeam.count;
    int remaining = count;
    ObjectItemBuf<ItemHolder<T>> 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) {
        ItemHolder<T> holder = generator.nextItem();
        buf.item = holder;
        buf.reset();
        int r = myTeam.workerRank(w);
        int tag = tagFor(w);
        comm.send(r, tag, buf);
        if (holder == null) {
            --remaining;
        } else {
            sendTaskInput(holder.myItem, comm, r, tag);
        }
    }
    // that worker.
    while (remaining > 0) {
        CommStatus status = comm.receive(null, tagRange, buf);
        ItemHolder<T> holder = buf.item;
        int r = status.fromRank;
        int tag = status.tag;
        int w = workerFor(tag);
        receiveTaskOutput(holder.myItem, comm, r, tag);
        holder = generator.nextItem();
        buf.item = holder;
        buf.reset();
        comm.send(r, tag, buf);
        if (holder == null) {
            --remaining;
        } else {
            sendTaskInput(holder.myItem, comm, r, tag);
        }
    }
}
Also used : Range(edu.rit.util.Range)

Example 37 with Range

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

the class WorkerIntegerStrideForLoop 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<Range> buf = ObjectBuf.buffer();
    for (; ; ) {
        comm.receive(r, tag, buf);
        Range 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 : Range(edu.rit.util.Range)

Example 38 with Range

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

the class FixedIntegerSchedule method next.

/**
 * {@inheritDoc}
 *
 * Obtain the next chunk of iterations for the given thread index. If there
 * are more iterations, a range object is returned whose lower bound, upper
 * bound, and stride specify the chunk of iterations to perform. The
 * returned range object's stride is the same as that given to the
 * <TT>start()</TT> method. The returned range object's lower bound and
 * upper bound are contained within the range given to the <TT>start()</TT>
 * method. If there are no more iterations, null is returned.
 * <P>
 * The <TT>next()</TT> method is called by multiple parallel team threads in
 * the Parallel Java middleware. The <TT>next()</TT> method must be multiple
 * thread safe.
 */
public Range next(int theThreadIndex) {
    Range chunk = myChunk[theThreadIndex];
    myChunk[theThreadIndex] = null;
    return chunk;
}
Also used : Range(edu.rit.util.Range)

Example 39 with Range

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

the class WorkerIntegerStrideForLoop 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(Range range, IntegerSchedule sch) throws IOException {
    int count = myTeam.count;
    sch.start(count, range);
    int remaining = count;
    ObjectItemBuf<Range> 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) {
        Range 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);
        Range 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 : Range(edu.rit.util.Range)

Example 40 with Range

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

the class WorkerIntegerStrideForLoop 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(Range range, IntegerSchedule 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) {
        Range 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) {
        Range chunk = sch.next(w);
        if (chunk != null) {
            receiveTaskOutput(chunk, comm, myTeam.workerRank(w), tagFor(w));
        }
    }
}
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