Search in sources :

Example 1 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    for (long i = lFrom; i <= lTo; ) {
        K = determineNextBatchSize(R, P);
        R -= (K * P);
        type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
        // for each logical processor
        for (int j = 0; j < P; j++) {
            if (// no more iterations
            i > lTo)
                break;
            // create new task and add to list of tasks
            Task lTask = new Task(_iterVarName, type);
            tasks.addLast(lTask);
            // add iterations to task
            if (type == TaskType.SET) {
                // value based tasks
                for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
            } else {
                // determine end of task
                long to = Math.min(i + (K - 1) * lIncr, lTo);
                // range based tasks
                // from
                lTask.addIteration(new IntObject(i));
                // to
                lTask.addIteration(new IntObject(to));
                // increment
                lTask.addIteration(new IntObject(lIncr));
                i = to + lIncr;
            }
        }
    }
    return tasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) LinkedList(java.util.LinkedList)

Example 2 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public long createTasks(LocalTaskQueue<Task> queue) {
    long numCreatedTasks = 0;
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    try {
        for (long i = lFrom; i <= lTo; ) {
            K = determineNextBatchSize(R, P);
            R -= (K * P);
            type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
            // for each logical processor
            for (int j = 0; j < P; j++) {
                if (// no more iterations
                i > lTo)
                    break;
                // create new task and add to list of tasks
                Task lTask = new Task(_iterVarName, type);
                // add iterations to task
                if (type == TaskType.SET) {
                    // value based tasks
                    for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
                } else {
                    // determine end of task
                    long to = Math.min(i + (K - 1) * lIncr, lTo);
                    // range based tasks
                    // from
                    lTask.addIteration(new IntObject(i));
                    // to
                    lTask.addIteration(new IntObject(to));
                    // increment
                    lTask.addIteration(new IntObject(lIncr));
                    i = to + lIncr;
                }
                // add task to queue (after all iteration added for preventing raise conditions)
                queue.enqueueTask(lTask);
                numCreatedTasks++;
            }
        }
        // mark end of task input stream
        queue.closeInput();
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return numCreatedTasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project systemml by apache.

the class TaskPartitionerFixedsize method createTasks.

@Override
public long createTasks(LocalTaskQueue<Task> queue) {
    long numCreatedTasks = 0;
    // range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && _taskSize > 3) ? TaskType.RANGE : TaskType.SET;
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    long lfnp1 = _firstnPlus1;
    try {
        for (long i = lFrom; i <= lTo; ) {
            // create new task and add to list of tasks
            Task lTask = new Task(_iterVarName, type);
            // correction for static partitioner
            int corr = (lfnp1-- > 0) ? 1 : 0;
            // (last task might have less)
            if (type == TaskType.SET) {
                // value based tasks
                for (long j = 0; j < _taskSize + corr && i <= lTo; j++, i += lIncr) lTask.addIteration(new IntObject(i));
            } else {
                // determine end of task
                long to = Math.min(i + (_taskSize - 1 + corr) * lIncr, lTo);
                // range based tasks
                // from
                lTask.addIteration(new IntObject(i));
                // to
                lTask.addIteration(new IntObject(to));
                // increment
                lTask.addIteration(new IntObject(lIncr));
                i = to + lIncr;
            }
            // add task to queue (after all iteration added for preventing raise conditions)
            queue.enqueueTask(lTask);
            numCreatedTasks++;
        }
        // mark end of task input stream
        queue.closeInput();
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return numCreatedTasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project incubator-systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public long createTasks(LocalTaskQueue<Task> queue) {
    long numCreatedTasks = 0;
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    try {
        for (long i = lFrom; i <= lTo; ) {
            K = determineNextBatchSize(R, P);
            R -= (K * P);
            type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
            // for each logical processor
            for (int j = 0; j < P; j++) {
                if (// no more iterations
                i > lTo)
                    break;
                // create new task and add to list of tasks
                Task lTask = new Task(_iterVarName, type);
                // add iterations to task
                if (type == TaskType.SET) {
                    // value based tasks
                    for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
                } else {
                    // determine end of task
                    long to = Math.min(i + (K - 1) * lIncr, lTo);
                    // range based tasks
                    // from
                    lTask.addIteration(new IntObject(i));
                    // to
                    lTask.addIteration(new IntObject(to));
                    // increment
                    lTask.addIteration(new IntObject(lIncr));
                    i = to + lIncr;
                }
                // add task to queue (after all iteration added for preventing raise conditions)
                queue.enqueueTask(lTask);
                numCreatedTasks++;
            }
        }
        // mark end of task input stream
        queue.closeInput();
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return numCreatedTasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project incubator-systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    for (long i = lFrom; i <= lTo; ) {
        K = determineNextBatchSize(R, P);
        R -= (K * P);
        type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
        // for each logical processor
        for (int j = 0; j < P; j++) {
            if (// no more iterations
            i > lTo)
                break;
            // create new task and add to list of tasks
            Task lTask = new Task(_iterVarName, type);
            tasks.addLast(lTask);
            // add iterations to task
            if (type == TaskType.SET) {
                // value based tasks
                for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
            } else {
                // determine end of task
                long to = Math.min(i + (K - 1) * lIncr, lTo);
                // range based tasks
                // from
                lTask.addIteration(new IntObject(i));
                // to
                lTask.addIteration(new IntObject(to));
                // increment
                lTask.addIteration(new IntObject(lIncr));
                i = to + lIncr;
            }
        }
    }
    return tasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) LinkedList(java.util.LinkedList)

Aggregations

TaskType (org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType)8 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)8 LinkedList (java.util.LinkedList)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4