Search in sources :

Example 16 with TaskSchedulerException

use of edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException in project twister2 by DSC-SPIDAL.

the class RoundRobinTaskScheduler method roundRobinSchedulingAlgorithm.

/**
 * This method retrieves the parallel task map and the total number of task instances for the task
 * vertex set. Then, it will allocate the instances into the number of containers allocated for
 * the task in a round robin fashion.
 */
private Map<Integer, List<TaskInstanceId>> roundRobinSchedulingAlgorithm(ComputeGraph graph, int numberOfContainers) throws TaskSchedulerException {
    Map<Integer, List<TaskInstanceId>> roundrobinAllocation = new LinkedHashMap<>();
    for (int i = 0; i < numberOfContainers; i++) {
        roundrobinAllocation.put(i, new ArrayList<>());
    }
    Set<Vertex> taskVertexSet = new LinkedHashSet<>(graph.getTaskVertexSet());
    TreeSet<Vertex> orderedTaskSet = new TreeSet<>(new VertexComparator());
    orderedTaskSet.addAll(taskVertexSet);
    TaskAttributes taskAttributes = new TaskAttributes();
    int globalTaskIndex = 0;
    for (Vertex vertex : taskVertexSet) {
        int totalTaskInstances;
        if (!graph.getNodeConstraints().isEmpty()) {
            totalTaskInstances = taskAttributes.getTotalNumberOfInstances(vertex, graph.getNodeConstraints());
        } else {
            totalTaskInstances = taskAttributes.getTotalNumberOfInstances(vertex);
        }
        if (!graph.getNodeConstraints().isEmpty()) {
            int instancesPerWorker = taskAttributes.getInstancesPerWorker(graph.getGraphConstraints());
            int maxTaskInstancesPerContainer = 0;
            int containerIndex;
            for (int i = 0; i < totalTaskInstances; i++) {
                containerIndex = i % numberOfContainers;
                if (maxTaskInstancesPerContainer < instancesPerWorker) {
                    roundrobinAllocation.get(containerIndex).add(new TaskInstanceId(vertex.getName(), globalTaskIndex, i));
                    ++maxTaskInstancesPerContainer;
                } else {
                    throw new TaskSchedulerException("Task Scheduling couldn't be possible for the present" + "configuration, please check the number of workers, " + "maximum instances per worker");
                }
            }
        } else {
            String task = vertex.getName();
            int containerIndex;
            for (int i = 0; i < totalTaskInstances; i++) {
                containerIndex = i % numberOfContainers;
                roundrobinAllocation.get(containerIndex).add(new TaskInstanceId(task, globalTaskIndex, i));
            }
        }
        globalTaskIndex++;
    }
    return roundrobinAllocation;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) LinkedHashMap(java.util.LinkedHashMap) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) TaskAttributes(edu.iu.dsc.tws.tsched.utils.TaskAttributes) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)16 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)8 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)7 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)6 ArrayList (java.util.ArrayList)6 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)5 TreeSet (java.util.TreeSet)5 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)4 TaskAttributes (edu.iu.dsc.tws.tsched.utils.TaskAttributes)4 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)3 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)3 Config (edu.iu.dsc.tws.api.config.Config)3 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2