use of edu.iu.dsc.tws.comms.stream.SAllReduce in project twister2 by DSC-SPIDAL.
the class SAllReduceExample method compute.
@Override
protected void compute(WorkerEnvironment workerEnv) {
LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
// create the communication
reduce = new SAllReduce(workerEnv.getCommunicator(), logicalPlanBuilder, MessageTypes.INTEGER_ARRAY, new ReduceOperationFunction(Op.SUM, MessageTypes.INTEGER_ARRAY), new FinalSingularReceiver());
Set<Integer> tasksOfExecutor = logicalPlanBuilder.getSourcesOnThisWorker();
for (int t : tasksOfExecutor) {
finishedSources.put(t, false);
}
sourcesDone = tasksOfExecutor.size() == 0;
Set<Integer> targetTasksOfExecutor = logicalPlanBuilder.getTargetsOnThisWorker();
for (int taskId : targetTasksOfExecutor) {
if (logicalPlanBuilder.getTargets().contains(taskId)) {
reduceDone = false;
}
if (workerId == 0) {
receiverInWorker0 = taskId;
}
}
this.resultsVerifier = new ResultsVerifier<>(inputDataArray, (array, args) -> {
int sourcesCount = jobParameters.getTaskStages().get(0);
return GeneratorUtils.multiplyIntArray(array, sourcesCount);
}, IntArrayComparator.getInstance());
// 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