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;
}
Aggregations