use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BKeyedPartitionExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv);
// create the communication
partition = new BKeyedPartition(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER, MessageTypes.INTEGER_ARRAY, new PartitionReceiver(), new SimpleKeyBasedSelector());
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
// now initialize the workers
this.resultsVerifier = new ResultsVerifier<>(inputDataArray, (ints, args) -> {
int lowestTarget = logicalPlanBuilder.getTargets().stream().min(Comparator.comparingInt(o -> (Integer) o)).get();
int target = Integer.parseInt(args.get("target").toString());
Set<Integer> keysRoutedToThis = new HashSet<>();
for (int i = 0; i < jobParameters.getTotalIterations(); i++) {
if (i % logicalPlanBuilder.getTargets().size() == target - lowestTarget) {
keysRoutedToThis.add(i);
}
}
List<Tuple<Integer, int[]>> expectedData = new ArrayList<>();
for (Integer key : keysRoutedToThis) {
for (int i = 0; i < logicalPlanBuilder.getSources().size(); i++) {
expectedData.add(new Tuple<>(key, ints));
}
}
return expectedData.iterator();
}, new IteratorComparator<>(new TupleComparator<>(// any int
(d1, d2) -> true, IntArrayComparator.getInstance())));
LOG.log(Level.INFO, String.format("%d Sources %s target %d this %s", workerId, logicalPlanBuilder.getSources(), 1, tasksOfExecutor));
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new KeyedBenchWorker.MapWorker(t));
mapThread.start();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BTAllToAll method execute.
@Override
public void execute(Config config, JobAPI.Job job, IWorkerController workerController, IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
this.jobParameters = JobParameters.build(config);
// create a worker environment
this.wEnv = WorkerEnvironment.init(config, job, workerController, persistentVolume, volatileVolume);
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), wEnv).withFairDistribution();
RootAllocator rootAllocator = new RootAllocator();
IntVector intVector = new IntVector("fist", rootAllocator);
Float8Vector float8Vector = new Float8Vector("second", rootAllocator);
for (int i = 0; i < 1000; i++) {
intVector.setSafe(i, i);
float8Vector.setSafe(i, i);
}
intVector.setValueCount(1000);
float8Vector.setValueCount(1000);
List<Field> fieldList = Arrays.asList(intVector.getField(), float8Vector.getField());
Schema schema = new Schema(fieldList);
Table t = new ArrowTable(schema, Arrays.asList(new FieldVector[] { intVector, float8Vector }));
allToAll = new ArrowAllToAll(wEnv.getConfig(), wEnv.getWorkerController(), logicalPlanBuilder.getSources(), logicalPlanBuilder.getTargets(), logicalPlanBuilder.build(), wEnv.getCommunicator().nextEdge(), new ArrowReceiver(), schema, rootAllocator);
for (int i : logicalPlanBuilder.getTargets()) {
allToAll.insert(t, i);
}
for (int s : logicalPlanBuilder.getSourcesOnThisWorker()) {
allToAll.finish(s);
}
while (!allToAll.isComplete()) {
// wait
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BDJoinExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
join = new BJoin(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER, MessageTypes.INTEGER_ARRAY, MessageTypes.INTEGER_ARRAY, new JoinReceiver(), new SimpleKeyBasedSelector(), true, Comparator.comparingInt(o -> (Integer) o), CommunicationContext.JoinType.INNER, CommunicationContext.JoinAlgorithm.SORT);
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
// now initialize the workers
LOG.log(Level.INFO, String.format("%d Sources %s target %d this %s", workerId, logicalPlanBuilder.getSources(), 1, tasksOfExecutor));
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new MapWorker(t));
mapThread.start();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BKeyedGatherExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv);
// create the communication
keyedGather = new BKeyedGather(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER, MessageTypes.INTEGER_ARRAY, new FinalReduceReceiver(), new SimpleKeyBasedSelector());
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
for (int t : tasksOfExecutor) {
finishedSources.put(t, false);
}
if (tasksOfExecutor.size() == 0) {
sourcesDone = true;
}
this.resultsVerifier = new ResultsVerifier<>(inputDataArray, (ints, args) -> {
int lowestTarget = logicalPlanBuilder.getTargets().stream().min(Comparator.comparingInt(o -> (Integer) o)).get();
int target = Integer.valueOf(args.get("target").toString());
Set<Integer> keysRoutedToThis = new HashSet<>();
for (int i = 0; i < jobParameters.getTotalIterations(); i++) {
if (i % logicalPlanBuilder.getTargets().size() == target - lowestTarget) {
keysRoutedToThis.add(i);
}
}
List<int[]> dataForEachKey = new ArrayList<>();
for (int i = 0; i < logicalPlanBuilder.getSources().size(); i++) {
dataForEachKey.add(ints);
}
List<Tuple<Integer, Iterator<int[]>>> expectedData = new ArrayList<>();
for (Integer key : keysRoutedToThis) {
expectedData.add(new Tuple<>(key, dataForEachKey.iterator()));
}
return expectedData.iterator();
}, new IteratorComparator<>(new TupleComparator<>(// any int
(d1, d2) -> true, new IteratorComparator<>(IntArrayComparator.getInstance()))));
LOG.log(Level.INFO, String.format("%d Sources %s target %d this %s", workerId, logicalPlanBuilder.getSources(), 1, tasksOfExecutor));
// now initialize the workers
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new MapWorker(t));
mapThread.start();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BReduceExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
reduce = new BReduce(workerEnv.getCommunicator(), logicalPlanBuilder, new ReduceOperationFunction(Op.SUM, MessageTypes.INTEGER_ARRAY), new FinalSingularReceiver(), MessageTypes.INTEGER_ARRAY);
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
for (int t : tasksOfExecutor) {
finishedSources.put(t, false);
}
if (tasksOfExecutor.size() == 0) {
sourcesDone = true;
}
this.resultsVerifier = new ResultsVerifier<>(inputDataArray, (ints, args) -> GeneratorUtils.multiplyIntArray(ints, jobParameters.getTotalIterations() * logicalPlanBuilder.getSources().size()), IntArrayComparator.getInstance());
LOG.log(Level.INFO, String.format("%d Sources %s target %d this %s", workerId, logicalPlanBuilder.getSources(), logicalPlanBuilder.getTargets().iterator().next(), tasksOfExecutor));
// now initialize the workers
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new MapWorker(t));
mapThread.start();
}
}
Aggregations