use of edu.iu.dsc.tws.api.compute.modifiers.Receptor in project twister2 by DSC-SPIDAL.
the class TaskExecutor method distributeData.
/**
* This method distributes collected {@link DataPartition}s to the
* intended {@link Receptor}s
*/
public static void distributeData(ExecutionPlan executionPlan, Map<String, DataObject> dataMap) {
Map<Integer, INodeInstance> nodes = executionPlan.getNodes();
if (nodes != null) {
nodes.forEach((id, node) -> {
INode task = node.getNode();
if (task instanceof Receptor) {
Set<String> receivableNames = ((Receptor) task).getReceivableNames();
for (String receivableName : receivableNames) {
DataObject dataObject = dataMap.get(receivableName);
if (dataObject == null) {
throw new Twister2RuntimeException("Couldn't find input data" + receivableName + " for task " + node.getId());
}
DataPartition partition = dataObject.getPartition(node.getIndex());
if (partition == null) {
throw new Twister2RuntimeException("Couldn't find input data" + receivableName + " for task index " + node.getIndex() + " of task" + node.getId());
}
((Receptor) task).add(receivableName, dataObject);
((Receptor) task).add(receivableName, partition);
}
}
});
}
}
use of edu.iu.dsc.tws.api.compute.modifiers.Receptor in project twister2 by DSC-SPIDAL.
the class BatchTaskScheduler method batchSchedulingAlgorithm.
private Map<Integer, List<TaskInstanceId>> batchSchedulingAlgorithm(ComputeGraph graph, int numberOfContainers) throws TaskSchedulerException {
Set<Vertex> taskVertexSet = new LinkedHashSet<>(graph.getTaskVertexSet());
TreeSet<Vertex> orderedTaskSet = new TreeSet<>(new VertexComparator());
orderedTaskSet.addAll(taskVertexSet);
IntStream.range(0, numberOfContainers).forEach(i1 -> batchTaskAllocation.put(i1, new ArrayList<>()));
int globalTaskIndex = 0;
if (dependentGraphs) {
for (Vertex vertex : taskVertexSet) {
INode iNode = vertex.getTask();
if (iNode instanceof Receptor) {
validateReceptor(graph, vertex);
}
dependentTaskWorkerAllocation(graph, vertex, numberOfContainers, globalTaskIndex);
globalTaskIndex++;
}
} else {
for (Vertex vertex : taskVertexSet) {
INode iNode = vertex.getTask();
if (iNode instanceof Collector) {
((Collector) iNode).getCollectibleNames().forEach(key -> collectibleNameMap.put(key, vertex.getParallelism()));
} else if (iNode instanceof Receptor) {
((Receptor) iNode).getReceivableNames().forEach(key -> receivableNameMap.put(key, vertex.getParallelism()));
validateParallelism();
}
independentTaskWorkerAllocation(graph, vertex, numberOfContainers, globalTaskIndex);
globalTaskIndex++;
}
}
return batchTaskAllocation;
}
use of edu.iu.dsc.tws.api.compute.modifiers.Receptor in project twister2 by DSC-SPIDAL.
the class TaskExecutor method addInput.
/**
* Add input to the the task instances
*
* @param graph task graph
* @param plan execution plan
* @param taskName task name
* @param inputKey inputkey
* @param input input
* @deprecated Inputs are automatically handled now
*/
@Deprecated
public void addInput(ComputeGraph graph, ExecutionPlan plan, String taskName, String inputKey, DataObject<?> input) {
Map<Integer, INodeInstance> nodes = plan.getNodes(taskName);
if (nodes == null) {
return;
}
for (Map.Entry<Integer, INodeInstance> e : nodes.entrySet()) {
INodeInstance node = e.getValue();
INode task = node.getNode();
if (task instanceof Receptor) {
((Receptor) task).add(inputKey, input);
} else {
throw new RuntimeException("Cannot add input to non input instance: " + node);
}
}
}
use of edu.iu.dsc.tws.api.compute.modifiers.Receptor in project twister2 by DSC-SPIDAL.
the class TaskExecutor method addSourceInput.
/**
* Add input to the the task instances
*
* @param graph task graph
* @param plan execution plan
* @param inputKey inputkey
* @param input input
* @deprecated Inputs are handled automatically now
*/
@Deprecated
public void addSourceInput(ComputeGraph graph, ExecutionPlan plan, String inputKey, DataObject<Object> input) {
Map<Integer, INodeInstance> nodes = plan.getNodes();
if (nodes == null) {
throw new RuntimeException(String.format("%d Failed to set input for non-existing " + "existing sources: %s", workerID, plan.getNodeNames()));
}
for (Map.Entry<Integer, INodeInstance> e : nodes.entrySet()) {
INodeInstance node = e.getValue();
INode task = node.getNode();
if (task instanceof Receptor && task instanceof ISource) {
((Receptor) task).add(inputKey, input);
}
}
}
Aggregations