Search in sources :

Example 61 with Range

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

the class ParallelRegion method execute.

/**
 * Execute a parallel for loop within this parallel region. For further
 * information, see class {@linkplain IntegerStrideForLoop}. 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. At
 * the end of the parallel for loop, the parallel team threads encounter a
 * barrier, and their behavior depends on the given {@linkplain
 * BarrierAction}.
 * <P>
 * <I>Note:</I> Either all threads in the parallel 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 Parallel for loop.
 * @param action Barrier action.
 * @exception IllegalArgumentException (unchecked exception) Thrown if
 * <TT>stride</TT> &lt; 1.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theLoop</TT> is null. Thrown if
 * <TT>action</TT> is null.
 * @exception IllegalStateException (unchecked exception) Thrown if no
 * parallel team is executing this parallel 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, IntegerStrideForLoop theLoop, BarrierAction action) throws Exception {
    // Verify preconditions.
    if (stride <= 0) {
        throw new IllegalArgumentException("ParallelRegion.execute(): Stride = " + stride + " illegal");
    }
    if (theLoop == null) {
        throw new NullPointerException("ParallelRegion.execute(): Parallel for loop is null");
    }
    if (action == null) {
        throw new NullPointerException("ParallelRegion.execute(): Barrier action is null");
    }
    if (myTeam == null) {
        throw new IllegalStateException("ParallelRegion.execute(): No parallel team executing");
    }
    try {
        // Record parallel team.
        theLoop.myTeam = this.myTeam;
        // Get current parallel team thread.
        ParallelTeamThread currentThread = getCurrentThread();
        int currentIndex = currentThread.myIndex;
        // Do top-of-parallel-construct processing.
        IntegerSchedule schedule = null;
        if (currentThread.arriveAtParallelConstruct()) {
            // each team thread.
            try {
                schedule = theLoop.schedule();
                schedule.commonStart(myTeam.K, new Range(first, last, stride));
                for (ParallelTeamThread thread : myTeam.myThread) {
                    thread.setIntegerSchedule(schedule);
                }
            } catch (Throwable exc) {
                for (ParallelTeamThread thread : myTeam.myThread) {
                    thread.setConstructException(exc);
                }
            }
        }
        // Get the shared parallel for loop schedule object.
        schedule = currentThread.getIntegerSchedule();
        theLoop.mySchedule = schedule;
        // Prepare to catch exceptions thrown by the parallel for loop body.
        Throwable runException = null;
        try {
            // Perform per-thread initialization.
            theLoop.start();
            // Repeatedly get and process a chunk of loop iterations.
            Range chunk;
            while ((chunk = schedule.commonNext(currentIndex)) != null) {
                theLoop.commonRun(chunk.lb(), chunk.ub(), chunk.stride());
            }
            // Perform per-thread finalization.
            theLoop.finish();
        } catch (Throwable exc) {
            runException = exc;
            schedule.myBreak = true;
        }
        // Barrier synchronization.
        action.doBarrier(currentThread);
        // Propagate any exception thrown by the run() method.
        ParallelTeam.rethrow(runException);
    } finally {
        // Forget parallel team.
        theLoop.myTeam = null;
        theLoop.mySchedule = null;
    }
}
Also used : Range(edu.rit.util.Range) LongRange(edu.rit.util.LongRange)

Example 62 with Range

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

the class Signed8BitIntegerBuf method buffer.

/**
 * Create a buffer for the entire given integer matrix. The returned buffer
 * encompasses all the rows and all the columns in
 * <TT>theMatrix</TT>.
 *
 * @param theMatrix Matrix.
 * @return Buffer.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theMatrix</TT> is null.
 */
public static Signed8BitIntegerBuf buffer(int[][] theMatrix) {
    if (theMatrix == null) {
        throw new NullPointerException("Signed8BitIntegerBuf.buffer(): theMatrix is null");
    }
    int nr = Arrays.rowLength(theMatrix);
    int nc = Arrays.colLength(theMatrix, 0);
    return new Signed8BitIntegerMatrixBuf_1(theMatrix, new Range(0, nr - 1), new Range(0, nc - 1));
}
Also used : Signed8BitIntegerMatrixBuf_1(edu.rit.mp.buf.Signed8BitIntegerMatrixBuf_1) Range(edu.rit.util.Range)

Example 63 with Range

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

the class BooleanBuf method buffer.

/**
 * Create a buffer for the entire given Boolean matrix. The returned buffer
 * encompasses all the rows and all the columns in <TT>theMatrix</TT>.
 *
 * @param theMatrix Matrix.
 * @return Buffer.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theMatrix</TT> is null.
 */
public static BooleanBuf buffer(boolean[][] theMatrix) {
    if (theMatrix == null) {
        throw new NullPointerException("BooleanBuf.buffer(): theMatrix is null");
    }
    int nr = Arrays.rowLength(theMatrix);
    int nc = Arrays.colLength(theMatrix, 0);
    return new BooleanMatrixBuf_1(theMatrix, new Range(0, nr - 1), new Range(0, nc - 1));
}
Also used : Range(edu.rit.util.Range) BooleanMatrixBuf_1(edu.rit.mp.buf.BooleanMatrixBuf_1)

Example 64 with Range

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

the class ByteBuf method patchBuffers.

/**
 * Create an array of buffers for multiple patches of the given byte matrix.
 * The length of the returned buffer array is equal to the length of
 * <TT>theRowRanges</TT> times the length of <TT>theColRanges</TT>. Each
 * element of the returned buffer array encompasses the rows given in one
 * element of <TT>theRowRanges</TT> array, and the columns given in one
 * element of <TT>theColRanges</TT> array, in all possible combinations, of
 * <TT>theMatrix</TT>. Each range's stride may be 1 or greater than 1.
 *
 * @param theMatrix Matrix.
 * @param theRowRanges Array of ranges of rows to include.
 * @param theColRanges Array of ranges of columns to include.
 * @return Array of buffers.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theMatrix</TT> is null,
 * <TT>theRowRanges</TT> or any element thereof is null, or
 * <TT>theColRanges</TT> or any element thereof is null.
 * @exception IndexOutOfBoundsException (unchecked exception) Thrown if
 * <TT>theMatrix</TT>'s allocation does not include any element of
 * <TT>theRowRanges</TT> or
 * <TT>theColRanges</TT>.
 */
public static ByteBuf[] patchBuffers(byte[][] theMatrix, Range[] theRowRanges, Range[] theColRanges) {
    int m = theRowRanges.length;
    int n = theColRanges.length;
    ByteBuf[] result = new ByteBuf[m * n];
    int k = 0;
    for (int i = 0; i < m; ++i) {
        Range rowrange = theRowRanges[i];
        for (int j = 0; j < n; ++j) {
            result[k++] = patchBuffer(theMatrix, rowrange, theColRanges[j]);
        }
    }
    return result;
}
Also used : SharedByteBuf(edu.rit.mp.buf.SharedByteBuf) EmptyByteBuf(edu.rit.mp.buf.EmptyByteBuf) Range(edu.rit.util.Range)

Example 65 with Range

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

the class DoubleBuf method patchBuffers.

/**
 * Create an array of buffers for multiple patches of the given double
 * matrix. The length of the returned buffer array is equal to the length of
 * <TT>theRowRanges</TT> times the length of <TT>theColRanges</TT>. Each
 * element of the returned buffer array encompasses the rows given in one
 * element of <TT>theRowRanges</TT> array, and the columns given in one
 * element of <TT>theColRanges</TT> array, in all possible combinations, of
 * <TT>theMatrix</TT>. Each range's stride may be 1 or greater than 1.
 *
 * @param theMatrix Matrix.
 * @param theRowRanges Array of ranges of rows to include.
 * @param theColRanges Array of ranges of columns to include.
 * @return Array of buffers.
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>theMatrix</TT> is null,
 * <TT>theRowRanges</TT> or any element thereof is null, or
 * <TT>theColRanges</TT> or any element thereof is null.
 * @exception IndexOutOfBoundsException (unchecked exception) Thrown if
 * <TT>theMatrix</TT>'s allocation does not include any element of
 * <TT>theRowRanges</TT> or
 * <TT>theColRanges</TT>.
 */
public static DoubleBuf[] patchBuffers(double[][] theMatrix, Range[] theRowRanges, Range[] theColRanges) {
    int m = theRowRanges.length;
    int n = theColRanges.length;
    DoubleBuf[] result = new DoubleBuf[m * n];
    int k = 0;
    for (int i = 0; i < m; ++i) {
        Range rowrange = theRowRanges[i];
        for (int j = 0; j < n; ++j) {
            result[k++] = patchBuffer(theMatrix, rowrange, theColRanges[j]);
        }
    }
    return result;
}
Also used : SharedDoubleBuf(edu.rit.mp.buf.SharedDoubleBuf) EmptyDoubleBuf(edu.rit.mp.buf.EmptyDoubleBuf) 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