Search in sources :

Example 51 with ComputeGraph

use of edu.iu.dsc.tws.api.compute.graph.ComputeGraph 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 52 with ComputeGraph

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

the class CDFWRuntime method handleExecuteMessage.

private boolean handleExecuteMessage(Any msg) {
    ISenderToDriver senderToDriver = JMWorkerAgent.getJMWorkerAgent().getDriverAgent();
    CDFWJobAPI.ExecuteMessage executeMessage;
    ExecutionPlan executionPlan;
    CDFWJobAPI.ExecuteCompletedMessage completedMessage = null;
    try {
        executeMessage = msg.unpack(CDFWJobAPI.ExecuteMessage.class);
        // get the subgraph from the map
        CDFWJobAPI.SubGraph subGraph = executeMessage.getGraph();
        ComputeGraph taskGraph = (ComputeGraph) serializer.deserialize(subGraph.getGraphSerialized().toByteArray());
        if (taskGraph == null) {
            LOG.severe(workerId + " Unable to find the subgraph " + subGraph.getName());
            return true;
        }
        // use the taskexecutor to create the execution plan
        executionPlan = taskExecutor.plan(taskGraph);
        taskExecutor.execute(taskGraph, executionPlan);
        // reuse the task executor execute
        completedMessage = CDFWJobAPI.ExecuteCompletedMessage.newBuilder().setSubgraphName(subGraph.getName()).build();
        if (!senderToDriver.sendToDriver(completedMessage)) {
            LOG.severe("Unable to send the subgraph completed message :" + completedMessage);
        }
    } catch (InvalidProtocolBufferException e) {
        LOG.log(Level.SEVERE, "Unable to unpack received message ", e);
    }
    return false;
}
Also used : ISenderToDriver(edu.iu.dsc.tws.api.resource.ISenderToDriver) ExecutionPlan(edu.iu.dsc.tws.api.compute.executor.ExecutionPlan) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CDFWJobAPI(edu.iu.dsc.tws.proto.system.job.CDFWJobAPI)

Example 53 with ComputeGraph

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

the class IterativeJob method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    ComputeEnvironment cEnv = ComputeEnvironment.init(workerEnv);
    TaskExecutor taskExecutor = cEnv.getTaskExecutor();
    int workerId = workerEnv.getWorkerId();
    Config config = workerEnv.getConfig();
    LOG.log(Level.INFO, "Task worker starting: " + workerId);
    IterativeSourceTask g = new IterativeSourceTask();
    PartitionTask r = new PartitionTask();
    ComputeGraphBuilder graphBuilder = ComputeGraphBuilder.newBuilder(config);
    graphBuilder.addSource("source", g, 4);
    ComputeConnection computeConnection = graphBuilder.addCompute("sink", r, 4);
    computeConnection.partition("source").viaEdge("partition").withDataType(MessageTypes.OBJECT);
    graphBuilder.setMode(OperationMode.BATCH);
    ComputeGraph graph = graphBuilder.build();
    ExecutionPlan plan = taskExecutor.plan(graph);
    IExecutor ex = taskExecutor.createExecution(graph, plan);
    for (int i = 0; i < 10; i++) {
        LOG.info("Starting iteration: " + i);
        taskExecutor.addInput(graph, plan, "source", "input", new DataObjectImpl<>(config));
        // this is a blocking call
        ex.execute();
        DataObject<Object> dataSet = taskExecutor.getOutput(graph, plan, "sink");
        DataPartition<Object>[] values = dataSet.getPartitions();
    }
    ex.closeExecution();
}
Also used : Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) ComputeGraphBuilder(edu.iu.dsc.tws.task.impl.ComputeGraphBuilder) ComputeConnection(edu.iu.dsc.tws.task.impl.ComputeConnection) ComputeEnvironment(edu.iu.dsc.tws.task.ComputeEnvironment) TaskExecutor(edu.iu.dsc.tws.task.impl.TaskExecutor) ExecutionPlan(edu.iu.dsc.tws.api.compute.executor.ExecutionPlan) IExecutor(edu.iu.dsc.tws.api.compute.executor.IExecutor) DataObject(edu.iu.dsc.tws.api.dataset.DataObject) DataPartition(edu.iu.dsc.tws.api.dataset.DataPartition)

Example 54 with ComputeGraph

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

the class SvmSgdRunner method initializeExecute.

/**
 * Initializing the execute method
 */
public void initializeExecute() {
    ComputeGraphBuilder builder = ComputeGraphBuilder.newBuilder(config);
    this.operationMode = this.svmJobParameters.isStreaming() ? OperationMode.STREAMING : OperationMode.BATCH;
    DataStreamer dataStreamer = new DataStreamer(this.operationMode, svmJobParameters.isDummy(), this.binaryBatchModel);
    SVMCompute svmCompute = new SVMCompute(this.binaryBatchModel, this.operationMode);
    SVMReduce svmReduce = new SVMReduce(this.operationMode);
    builder.addSource(Constants.SimpleGraphConfig.DATASTREAMER_SOURCE, dataStreamer, dataStreamerParallelism);
    ComputeConnection svmComputeConnection = builder.addCompute(Constants.SimpleGraphConfig.SVM_COMPUTE, svmCompute, svmComputeParallelism);
    ComputeConnection svmReduceConnection = builder.addCompute(Constants.SimpleGraphConfig.SVM_REDUCE, svmReduce, reduceParallelism);
    svmComputeConnection.direct(Constants.SimpleGraphConfig.DATASTREAMER_SOURCE).viaEdge(Constants.SimpleGraphConfig.DATA_EDGE).withDataType(MessageTypes.OBJECT);
    svmReduceConnection.reduce(Constants.SimpleGraphConfig.SVM_COMPUTE).viaEdge(Constants.SimpleGraphConfig.REDUCE_EDGE).withReductionFunction(new ReduceAggregator()).withDataType(MessageTypes.OBJECT);
    builder.setMode(operationMode);
    ComputeGraph graph = builder.build();
    ExecutionPlan plan = taskExecutor.plan(graph);
    taskExecutor.execute(graph, plan);
    LOG.info("Task Graph Executed !!! ");
    if (operationMode.equals(OperationMode.BATCH)) {
        DataObject<double[]> dataSet = taskExecutor.getOutput(graph, plan, Constants.SimpleGraphConfig.SVM_REDUCE);
        DataPartition<double[]> values = dataSet.getPartitions()[0];
        DataPartitionConsumer<double[]> dataPartitionConsumer = values.getConsumer();
        // LOG.info("Final Receive  : " + dataPartitionConsumer.hasNext());
        while (dataPartitionConsumer.hasNext()) {
            LOG.info("Final Aggregated Values Are:" + Arrays.toString(dataPartitionConsumer.next()));
        }
    }
}
Also used : SVMReduce(edu.iu.dsc.tws.examples.ml.svm.aggregate.SVMReduce) DataStreamer(edu.iu.dsc.tws.examples.ml.svm.streamer.DataStreamer) ReduceAggregator(edu.iu.dsc.tws.examples.ml.svm.aggregate.ReduceAggregator) ExecutionPlan(edu.iu.dsc.tws.api.compute.executor.ExecutionPlan) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) ComputeGraphBuilder(edu.iu.dsc.tws.task.impl.ComputeGraphBuilder) SVMCompute(edu.iu.dsc.tws.examples.ml.svm.compute.SVMCompute) ComputeConnection(edu.iu.dsc.tws.task.impl.ComputeConnection)

Example 55 with ComputeGraph

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

the class DataParallelWorker method execute.

@Override
public void execute() {
    ComputeGraphBuilder computeGraphBuilder = ComputeGraphBuilder.newBuilder(config);
    String inputDirectory = config.getStringValue(Constants.ARGS_INPUT_DIRECTORY);
    boolean shared = config.getBooleanValue(Constants.ARGS_SHARED_FILE_SYSTEM);
    int numFiles = config.getIntegerValue(Constants.ARGS_NUMBER_OF_FILES, 4);
    int size = config.getIntegerValue(Constants.ARGS_SIZE, 1000);
    int parallel = config.getIntegerValue(Constants.ARGS_PARALLEL, 2);
    if (!shared && workerId == 0) {
        try {
            DataGenerator.generateData("txt", new Path(inputDirectory), numFiles, size, 10);
        } catch (IOException e) {
            throw new RuntimeException("Failed to create data: " + inputDirectory);
        }
    }
    DataParallelTask task = new DataParallelTask();
    computeGraphBuilder.addSource("map", task, parallel);
    computeGraphBuilder.setMode(OperationMode.BATCH);
    ComputeGraph computeGraph = computeGraphBuilder.build();
    ExecutionPlan plan = taskExecutor.plan(computeGraph);
    taskExecutor.execute(computeGraph, plan);
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) ExecutionPlan(edu.iu.dsc.tws.api.compute.executor.ExecutionPlan) ComputeGraph(edu.iu.dsc.tws.api.compute.graph.ComputeGraph) ComputeGraphBuilder(edu.iu.dsc.tws.task.impl.ComputeGraphBuilder) IOException(java.io.IOException)

Aggregations

ComputeGraph (edu.iu.dsc.tws.api.compute.graph.ComputeGraph)89 ComputeConnection (edu.iu.dsc.tws.task.impl.ComputeConnection)40 ComputeGraphBuilder (edu.iu.dsc.tws.task.impl.ComputeGraphBuilder)39 TaskSchedulerClassTest (edu.iu.dsc.tws.tsched.utils.TaskSchedulerClassTest)38 ExecutionPlan (edu.iu.dsc.tws.api.compute.executor.ExecutionPlan)32 TaskSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskSchedulePlan)26 WorkerPlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerPlan)25 Test (org.junit.Test)25 WorkerSchedulePlan (edu.iu.dsc.tws.api.compute.schedule.elements.WorkerSchedulePlan)22 Map (java.util.Map)22 TaskInstancePlan (edu.iu.dsc.tws.api.compute.schedule.elements.TaskInstancePlan)20 Config (edu.iu.dsc.tws.api.config.Config)18 DataObject (edu.iu.dsc.tws.api.dataset.DataObject)9 ComputeEnvironment (edu.iu.dsc.tws.task.ComputeEnvironment)9 DataFlowGraph (edu.iu.dsc.tws.task.cdfw.DataFlowGraph)8 IExecutor (edu.iu.dsc.tws.api.compute.executor.IExecutor)7 JobConfig (edu.iu.dsc.tws.api.JobConfig)5 DataObjectSource (edu.iu.dsc.tws.task.dataobjects.DataObjectSource)5 HashMap (java.util.HashMap)5 Path (edu.iu.dsc.tws.api.data.Path)4