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);
}
}
}
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;
}
}
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, >= 1.
* @param theLoop Worker for loop.
* @exception IllegalArgumentException (unchecked exception) Thrown if
* <TT>stride</TT> < 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;
}
}
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;
}
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));
}
Aggregations