use of edu.iu.dsc.tws.api.compute.TaskPartitioner in project twister2 by DSC-SPIDAL.
the class TeraSort method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
int workerID = workerEnv.getWorkerId();
ComputeEnvironment cEnv = ComputeEnvironment.init(workerEnv);
Config config = workerEnv.getConfig();
resultsRecorder = new BenchmarkResultsRecorder(config, workerID == 0);
Timing.setDefaultTimingUnit(TimingUnit.MILLI_SECONDS);
final String filePath = config.getStringValue(ARG_INPUT_FILE, null);
final int keySize = config.getIntegerValue(ARG_KEY_SIZE, 10);
final int valueSize = config.getIntegerValue(ARG_VALUE_SIZE, 90);
// Sampling Graph : if file based only
TaskPartitioner taskPartitioner;
if (filePath != null) {
ComputeGraphBuilder samplingGraph = ComputeGraphBuilder.newBuilder(config);
samplingGraph.setMode(OperationMode.BATCH);
Sampler samplerTask = new Sampler();
samplingGraph.addSource(TASK_SAMPLER, samplerTask, config.getIntegerValue(ARG_TASKS_SOURCES, 4));
SamplerReduce samplerReduce = new SamplerReduce();
samplingGraph.addCompute(TASK_SAMPLER_REDUCE, samplerReduce, config.getIntegerValue(ARG_RESOURCE_INSTANCES, 4)).allreduce(TASK_SAMPLER).viaEdge(EDGE).withReductionFunction(byte[].class, (minMax1, minMax2) -> {
byte[] min1 = Arrays.copyOfRange(minMax1, 0, keySize);
byte[] max1 = Arrays.copyOfRange(minMax1, keySize, minMax1.length);
byte[] min2 = Arrays.copyOfRange(minMax2, 0, keySize);
byte[] max2 = Arrays.copyOfRange(minMax2, keySize, minMax2.length);
byte[] newMinMax = new byte[keySize * 2];
byte[] min = min1;
byte[] max = max1;
if (ByteArrayComparator.getInstance().compare(min1, min2) > 0) {
min = min2;
}
if (ByteArrayComparator.getInstance().compare(max1, max2) < 0) {
max = max2;
}
System.arraycopy(min, 0, newMinMax, 0, keySize);
System.arraycopy(max, 0, newMinMax, keySize, keySize);
return newMinMax;
});
ComputeGraph sampleGraphBuild = samplingGraph.build();
ExecutionPlan sampleTaskPlan = cEnv.getTaskExecutor().plan(sampleGraphBuild);
cEnv.getTaskExecutor().execute(sampleGraphBuild, sampleTaskPlan);
DataObject<byte[]> output = cEnv.getTaskExecutor().getOutput("sample-reduce");
LOG.info("Sample output received");
taskPartitioner = new TaskPartitionerForSampledData(output.getPartitions()[0].getConsumer().next(), keySize);
} else {
taskPartitioner = new TaskPartitionerForRandom();
}
// Sort Graph
ComputeGraphBuilder teraSortTaskGraph = ComputeGraphBuilder.newBuilder(config);
teraSortTaskGraph.setMode(OperationMode.BATCH);
BaseSource dataSource;
if (filePath == null) {
dataSource = new RandomDataSource();
} else {
dataSource = new FileDataSource();
}
teraSortTaskGraph.addSource(TASK_SOURCE, dataSource, config.getIntegerValue(ARG_TASKS_SOURCES, 4));
Receiver receiver = new Receiver();
KeyedGatherConfig keyedGatherConfig = teraSortTaskGraph.addCompute(TASK_RECV, receiver, config.getIntegerValue(ARG_TASKS_SINKS, 4)).keyedGather(TASK_SOURCE).viaEdge(EDGE).withDataType(MessageTypes.BYTE_ARRAY).withKeyType(MessageTypes.BYTE_ARRAY).withTaskPartitioner(taskPartitioner).useDisk(true).sortBatchByKey(ByteArrayComparator.getInstance()).groupBatchByKey(false);
if (config.getBooleanValue(ARG_FIXED_SCHEMA, false)) {
LOG.info("Using fixed schema feature with message size : " + (keySize + valueSize) + " and key size : " + keySize);
keyedGatherConfig.withMessageSchema(MessageSchema.ofSize(keySize + valueSize, keySize));
}
ComputeGraph computeGraph = teraSortTaskGraph.build();
ExecutionPlan executionPlan = cEnv.getTaskExecutor().plan(computeGraph);
cEnv.getTaskExecutor().execute(computeGraph, executionPlan);
cEnv.close();
LOG.info("Finished Sorting...");
}
use of edu.iu.dsc.tws.api.compute.TaskPartitioner in project twister2 by DSC-SPIDAL.
the class BTJoinExample method buildTaskGraph.
@Override
public ComputeGraphBuilder buildTaskGraph() {
List<Integer> taskStages = jobParameters.getTaskStages();
int sourceParallelism = taskStages.get(0);
int sinkParallelism = taskStages.get(1);
MessageType keyType = MessageTypes.INTEGER;
MessageType dataType = MessageTypes.INTEGER_ARRAY;
BaseSource source1 = new JoinSource(JoinRelation.LEFT);
BaseSource source2 = new JoinSource(JoinRelation.RIGHT);
ICompute r = new JoinSinkTask();
computeGraphBuilder.addSource(SOURCE, source1, sourceParallelism);
computeGraphBuilder.addSource(SOURCE2, source2, sourceParallelism);
computeConnection = computeGraphBuilder.addCompute(SINK, r, sinkParallelism);
computeConnection.innerJoin(SOURCE, SOURCE2, CommunicationContext.JoinAlgorithm.SORT).viaLeftEdge(LEFT_EDGE).viaRightEdge(RIGHT_EDGE).withKeyType(keyType).withLeftDataType(dataType).withRightDataType(dataType).withTaskPartitioner(new TaskPartitioner() {
private List<Integer> dst;
@Override
public void prepare(Set sources, Set destinations) {
this.dst = new ArrayList<>(destinations);
Collections.sort(this.dst);
}
@Override
public int partition(int source, Object data) {
return dst.get((Integer) data % dst.size());
}
@Override
public void commit(int source, int partition) {
}
}).withComparator(Integer::compareTo);
return computeGraphBuilder;
}
Aggregations