Search in sources :

Example 1 with Receptor

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);
                }
            }
        });
    }
}
Also used : INode(edu.iu.dsc.tws.api.compute.nodes.INode) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) DataObject(edu.iu.dsc.tws.api.dataset.DataObject) EmptyDataObject(edu.iu.dsc.tws.api.dataset.EmptyDataObject) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) INodeInstance(edu.iu.dsc.tws.api.compute.executor.INodeInstance) DataPartition(edu.iu.dsc.tws.api.dataset.DataPartition)

Example 2 with Receptor

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntStream(java.util.stream.IntStream) TaskInstanceId(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) TaskAttributes(edu.iu.dsc.tws.tsched.utils.TaskAttributes) INode(edu.iu.dsc.tws.api.compute.nodes.INode) HashMap(java.util.HashMap) Config(edu.iu.dsc.tws.api.config.Config) TaskSchedulerContext(edu.iu.dsc.tws.tsched.spi.common.TaskSchedulerContext) Resource(edu.iu.dsc.tws.api.compute.schedule.elements.Resource) TreeSet(java.util.TreeSet) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WorkerSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan) TaskInstanceMapCalculation(edu.iu.dsc.tws.tsched.spi.taskschedule.TaskInstanceMapCalculation) TaskSchedulePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) Map(java.util.Map) TaskInstancePlan(edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan) Collector(edu.iu.dsc.tws.api.compute.modifiers.Collector) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Logger(java.util.logging.Logger) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) List(java.util.List) ITaskScheduler(edu.iu.dsc.tws.api.compute.schedule.ITaskScheduler) Worker(edu.iu.dsc.tws.api.compute.schedule.elements.Worker) WorkerPlan(edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan) Edge(edu.iu.dsc.tws.api.compute.graph.Edge) Comparator(java.util.Comparator) TaskSchedulerException(edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException) Vertex(edu.iu.dsc.tws.api.compute.graph.Vertex) INode(edu.iu.dsc.tws.api.compute.nodes.INode) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Collector(edu.iu.dsc.tws.api.compute.modifiers.Collector)

Example 3 with Receptor

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);
        }
    }
}
Also used : INode(edu.iu.dsc.tws.api.compute.nodes.INode) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) INodeInstance(edu.iu.dsc.tws.api.compute.executor.INodeInstance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with Receptor

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);
        }
    }
}
Also used : INode(edu.iu.dsc.tws.api.compute.nodes.INode) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Receptor(edu.iu.dsc.tws.api.compute.modifiers.Receptor) INodeInstance(edu.iu.dsc.tws.api.compute.executor.INodeInstance) ISource(edu.iu.dsc.tws.api.compute.nodes.ISource) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Receptor (edu.iu.dsc.tws.api.compute.modifiers.Receptor)4 INode (edu.iu.dsc.tws.api.compute.nodes.INode)4 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)4 INodeInstance (edu.iu.dsc.tws.api.compute.executor.INodeInstance)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 TaskSchedulerException (edu.iu.dsc.tws.api.compute.exceptions.TaskSchedulerException)1 ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)1 Edge (edu.iu.dsc.tws.api.compute.graph.Edge)1 Vertex (edu.iu.dsc.tws.api.compute.graph.Vertex)1 Collector (edu.iu.dsc.tws.api.compute.modifiers.Collector)1 ISource (edu.iu.dsc.tws.api.compute.nodes.ISource)1 ITaskScheduler (edu.iu.dsc.tws.api.compute.schedule.ITaskScheduler)1 Resource (edu.iu.dsc.tws.api.compute.schedule.elements.Resource)1 TaskInstanceId (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstanceId)1 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)1 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)1 Worker (edu.iu.dsc.tws.api.compute.schedule.elements.Worker)1 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)1