Search in sources :

Example 6 with TaskType

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

the class TaskPartitionerFixedsize method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    // 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;
    for (long i = lFrom; i <= lTo; ) {
        // create new task and add to list of tasks
        Task lTask = new Task(_iterVarName, type);
        tasks.addLast(lTask);
        // 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;
        }
    }
    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 7 with TaskType

use of org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType in project incubator-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 8 with TaskType

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

the class TaskPartitionerFixedsize method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    // 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;
    for (long i = lFrom; i <= lTo; ) {
        // create new task and add to list of tasks
        Task lTask = new Task(_iterVarName, type);
        tasks.addLast(lTask);
        // 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;
        }
    }
    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