Search in sources :

Example 6 with TaskAttributes

use of edu.iu.dsc.tws.tsched.utils.TaskAttributes 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

TaskAttributes (edu.iu.dsc.tws.tsched.utils.TaskAttributes)6 TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)3 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)3 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 DataNodeLocatorUtils (edu.iu.dsc.tws.data.utils.DataNodeLocatorUtils)1 DataTransferTimeCalculator (edu.iu.dsc.tws.tsched.utils.DataTransferTimeCalculator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1