use of edu.iu.dsc.tws.api.dataset.DataPartition 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.dataset.DataPartition in project twister2 by DSC-SPIDAL.
the class TaskExecutor method collectData.
/**
* This method collects all the output from the provided {@link ExecutionPlan}.
* The partition IDs will be assigned just before adding the partitions to the {@link DataObject}
*/
public static void collectData(Config cfg, ExecutionPlan executionPlan, Map<String, DataObject> dataMap) {
Map<Integer, INodeInstance> nodes = executionPlan.getNodes();
Map<String, DataObject> dataObjectMapForPlan = new HashMap<>();
if (nodes != null) {
nodes.forEach((taskId, node) -> {
INode task = node.getNode();
if (task instanceof Collector) {
Set<String> collectibleNames = ((Collector) task).getCollectibleNames();
collectibleNames.forEach(name -> {
DataPartition partition = ((Collector) task).get(name);
// if this task outs only one partition and user has implemented no arg get() method
if (collectibleNames.size() == 1 && partition == null) {
partition = ((Collector) task).get();
}
if (partition != null) {
partition.setId(node.getIndex());
dataObjectMapForPlan.computeIfAbsent(name, n -> new DataObjectImpl<>(cfg)).addPartition(partition);
} else {
LOG.warning(String.format("Task index %d of task %d returned null for data %s", node.getIndex(), node.getId(), name));
}
});
}
});
}
dataMap.putAll(dataObjectMapForPlan);
}
use of edu.iu.dsc.tws.api.dataset.DataPartition 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();
}
Aggregations