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);
}
}
}
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();
}
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;
}
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);
}
}
}
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));
}
}
}
Aggregations