use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BGatherExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
if (jobParameters.getTargets() != 1) {
LOG.warning("Setting no of targets to 1. Found " + jobParameters.getTargets());
jobParameters.getTaskStages().set(1, 1);
}
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv);
// create the communication
gather = new BGather(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER_ARRAY, new FinalReduceReceiver(), false);
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) -> {
List<Tuple<Integer, int[]>> expectedData = new ArrayList<>();
for (Integer source : logicalPlanBuilder.getSources()) {
for (int i = 0; i < jobParameters.getTotalIterations(); i++) {
expectedData.add(new Tuple<>(source, ints));
}
}
return expectedData.iterator();
}, new IteratorComparator<>(new TupleComparator<>(IntComparator.getInstance(), 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();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BJoinStudentExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the join communication
join = new BJoin(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER, MessageTypes.OBJECT, MessageTypes.OBJECT, new JoinReceiver(), new SimpleKeyBasedSelector(), false, (o1, o2) -> {
if (o1 instanceof String && o2 instanceof String) {
return ((String) o1).compareTo((String) o2);
}
return 0;
}, 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 BPartitionExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
partition = new BPartition(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER_ARRAY, new PartitionReceiver(), new LoadBalanceSelector(), false);
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());
int toThisFromOneSource = jobParameters.getTotalIterations() / logicalPlanBuilder.getTargets().size();
if (jobParameters.getTotalIterations() % logicalPlanBuilder.getTargets().size() > (target - lowestTarget)) {
toThisFromOneSource++;
}
List<int[]> expectedData = new ArrayList<>();
for (int i = 0; i < toThisFromOneSource * logicalPlanBuilder.getSources().size(); i++) {
expectedData.add(ints);
}
return expectedData.iterator();
}, new IteratorComparator<>(IntArrayComparator.getInstance()));
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
// now initialize the workers
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new BenchWorker.MapWorker(t));
mapThread.start();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BAllReduceExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
Integer noOfSourceTasks = jobParameters.getTaskStages().get(0);
Set<Integer> sources = IntStream.range(0, noOfSourceTasks).boxed().collect(Collectors.toSet());
int noOfTargetTasks = jobParameters.getTaskStages().get(1);
Set<Integer> targets = IntStream.range(noOfSourceTasks, noOfTargetTasks + noOfSourceTasks).boxed().collect(Collectors.toSet());
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
reduce = new BAllReduce(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.getIterations() * sources.size()), IntArrayComparator.getInstance());
LOG.log(Level.INFO, String.format("%d Sources %s target %s this %s", workerId, sources, targets, tasksOfExecutor));
// now initialize the workers
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new BenchWorker.MapWorker(t));
mapThread.start();
}
}
use of edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder in project twister2 by DSC-SPIDAL.
the class BDirectExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
if (!jobParameters.getTaskStages().get(0).equals(jobParameters.getTaskStages().get(1))) {
int min = Math.min(jobParameters.getTaskStages().get(0), jobParameters.getTaskStages().get(1));
LOG.warning("Setting sources and sinks to " + min);
jobParameters.getTaskStages().set(0, min);
jobParameters.getTaskStages().set(1, min);
}
Integer noOfSourceTasks = jobParameters.getTaskStages().get(0);
List<Integer> sources = IntStream.range(0, noOfSourceTasks).boxed().collect(Collectors.toList());
Integer noOfTargetTasks = jobParameters.getTaskStages().get(1);
List<Integer> targets = IntStream.range(0, noOfTargetTasks).boxed().collect(Collectors.toList());
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
direct = new BDirect(workerEnv.getCommunicator(), logicalPlanBuilder, new DirectReceiver(), MessageTypes.INTEGER_ARRAY, false);
resultsVerifier = new ResultsVerifier<>(inputDataArray, (ints, args) -> {
List<int[]> expectedData = new ArrayList<>();
for (int i = 0; i < jobParameters.getTotalIterations(); i++) {
expectedData.add(ints);
}
return expectedData.iterator();
}, new IteratorComparator<>(IntArrayComparator.getInstance()));
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
for (int t : tasksOfExecutor) {
finishedSources.put(t, false);
}
if (tasksOfExecutor.size() == 0) {
sourcesDone = true;
}
// now initialize the workers
for (int t : tasksOfExecutor) {
// the map thread where data is produced
Thread mapThread = new Thread(new BenchWorker.MapWorker(t));
mapThread.start();
}
}
Aggregations