use of edu.iu.dsc.tws.task.impl.ComputeConnection 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();
}
use of edu.iu.dsc.tws.task.impl.ComputeConnection in project twister2 by DSC-SPIDAL.
the class TGUtils method buildWeightVectorTG.
public static ComputeGraph buildWeightVectorTG(Config config, int dataStreamerParallelism, SVMJobParameters svmJobParameters, OperationMode opMode) {
DataFileReplicatedReadSource dataFileReplicatedReadSource = new DataFileReplicatedReadSource(Context.TWISTER2_DIRECT_EDGE, svmJobParameters.getWeightVectorDataDir());
IterativeSVMWeightVectorObjectCompute weightVectorObjectCompute = new IterativeSVMWeightVectorObjectCompute(Context.TWISTER2_DIRECT_EDGE, 1, svmJobParameters.getFeatures());
IterativeSVMWeightVectorObjectDirectSink weightVectorObjectSink = new IterativeSVMWeightVectorObjectDirectSink();
ComputeGraphBuilder weightVectorComputeGraphBuilder = ComputeGraphBuilder.newBuilder(config);
weightVectorComputeGraphBuilder.addSource(Constants.SimpleGraphConfig.WEIGHT_VECTOR_OBJECT_SOURCE, dataFileReplicatedReadSource, dataStreamerParallelism);
ComputeConnection weightVectorComputeConnection = weightVectorComputeGraphBuilder.addCompute(Constants.SimpleGraphConfig.WEIGHT_VECTOR_OBJECT_COMPUTE, weightVectorObjectCompute, dataStreamerParallelism);
ComputeConnection weightVectorSinkConnection = weightVectorComputeGraphBuilder.addCompute(Constants.SimpleGraphConfig.WEIGHT_VECTOR_OBJECT_SINK, weightVectorObjectSink, dataStreamerParallelism);
weightVectorComputeConnection.direct(Constants.SimpleGraphConfig.WEIGHT_VECTOR_OBJECT_SOURCE).viaEdge(Context.TWISTER2_DIRECT_EDGE).withDataType(MessageTypes.OBJECT);
weightVectorSinkConnection.direct(Constants.SimpleGraphConfig.WEIGHT_VECTOR_OBJECT_COMPUTE).viaEdge(Context.TWISTER2_DIRECT_EDGE).withDataType(MessageTypes.DOUBLE_ARRAY);
weightVectorComputeGraphBuilder.setMode(opMode);
weightVectorComputeGraphBuilder.setTaskGraphName(IterativeSVMConstants.WEIGHT_VECTOR_LOADING_TASK_GRAPH);
return weightVectorComputeGraphBuilder.build();
}
use of edu.iu.dsc.tws.task.impl.ComputeConnection 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()));
}
}
}
use of edu.iu.dsc.tws.task.impl.ComputeConnection in project twister2 by DSC-SPIDAL.
the class MultiStageGraph method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
ComputeEnvironment cEnv = ComputeEnvironment.init(workerEnv);
GeneratorTask g = new GeneratorTask();
ReduceTask rt = new ReduceTask();
PartitionTask r = new PartitionTask();
ComputeGraphBuilder builder = ComputeGraphBuilder.newBuilder(workerEnv.getConfig());
builder.addSource("source", g, 4);
ComputeConnection pc = builder.addCompute("compute", r, 4);
pc.partition("source").viaEdge("partition-edge").withDataType(MessageTypes.OBJECT);
ComputeConnection rc = builder.addCompute("sink", rt, 1);
rc.reduce("compute").viaEdge("compute-edge").withReductionFunction((object1, object2) -> object1);
builder.setMode(OperationMode.STREAMING);
ComputeGraph graph = builder.build();
graph.setGraphName("MultiTaskGraph");
cEnv.getTaskExecutor().execute(graph, cEnv.getTaskExecutor().plan(graph));
}
use of edu.iu.dsc.tws.task.impl.ComputeConnection in project twister2 by DSC-SPIDAL.
the class KMeansConnectedDataflowExample method generateData.
private static DataFlowGraph generateData(Config config, String dataDirectory, String centroidDirectory, int dimension, int dsize, int csize, int workers, int parallel, DataFlowJobConfig jobConfig) {
DataGeneratorSource dataGeneratorSource = new DataGeneratorSource(Context.TWISTER2_DIRECT_EDGE, dsize, csize, dimension, dataDirectory, centroidDirectory);
DataGeneratorSink dataGeneratorSink = new DataGeneratorSink();
ComputeGraphBuilder dataGenerationGraphBuilder = ComputeGraphBuilder.newBuilder(config);
dataGenerationGraphBuilder.setTaskGraphName("DataGenerator");
dataGenerationGraphBuilder.addSource("datageneratorsource", dataGeneratorSource, parallel);
ComputeConnection dataObjectComputeConnection = dataGenerationGraphBuilder.addCompute("datageneratorsink", dataGeneratorSink, parallel);
dataObjectComputeConnection.direct("datageneratorsource").viaEdge(Context.TWISTER2_DIRECT_EDGE).withDataType(MessageTypes.OBJECT);
dataGenerationGraphBuilder.setMode(OperationMode.BATCH);
ComputeGraph dataObjectTaskGraph = dataGenerationGraphBuilder.build();
dataGenerationGraphBuilder.setTaskGraphName("datageneratorTG");
DataFlowGraph job = DataFlowGraph.newSubGraphJob("datageneratorTG", dataObjectTaskGraph).setWorkers(workers).addDataFlowJobConfig(jobConfig).setGraphType("non-iterative");
return job;
}
Aggregations