Search in sources :

Example 1 with BAllReduce

use of edu.iu.dsc.tws.comms.batch.BAllReduce 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();
    }
}
Also used : IntStream(java.util.stream.IntStream) IntArrayComparator(edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator) SingularReceiver(edu.iu.dsc.tws.api.comms.SingularReceiver) BAllReduce(edu.iu.dsc.tws.comms.batch.BAllReduce) GeneratorUtils(edu.iu.dsc.tws.examples.verification.GeneratorUtils) Set(java.util.Set) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder) Config(edu.iu.dsc.tws.api.config.Config) Timing(edu.iu.dsc.tws.examples.utils.bench.Timing) MessageTypes(edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes) Logger(java.util.logging.Logger) BenchWorker(edu.iu.dsc.tws.examples.comms.BenchWorker) Collectors(java.util.stream.Collectors) BenchmarkConstants(edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants) Level(java.util.logging.Level) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) Op(edu.iu.dsc.tws.api.comms.Op) ReduceOperationFunction(edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction) BenchmarkUtils(edu.iu.dsc.tws.examples.utils.bench.BenchmarkUtils) ResultsVerifier(edu.iu.dsc.tws.examples.verification.ResultsVerifier) Comparator(java.util.Comparator) ReduceOperationFunction(edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction) BenchWorker(edu.iu.dsc.tws.examples.comms.BenchWorker) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder) BAllReduce(edu.iu.dsc.tws.comms.batch.BAllReduce)

Aggregations

Op (edu.iu.dsc.tws.api.comms.Op)1 SingularReceiver (edu.iu.dsc.tws.api.comms.SingularReceiver)1 MessageTypes (edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes)1 Config (edu.iu.dsc.tws.api.config.Config)1 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)1 BAllReduce (edu.iu.dsc.tws.comms.batch.BAllReduce)1 ReduceOperationFunction (edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction)1 LogicalPlanBuilder (edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder)1 BenchWorker (edu.iu.dsc.tws.examples.comms.BenchWorker)1 BenchmarkConstants (edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants)1 BenchmarkUtils (edu.iu.dsc.tws.examples.utils.bench.BenchmarkUtils)1 Timing (edu.iu.dsc.tws.examples.utils.bench.Timing)1 GeneratorUtils (edu.iu.dsc.tws.examples.verification.GeneratorUtils)1 ResultsVerifier (edu.iu.dsc.tws.examples.verification.ResultsVerifier)1 IntArrayComparator (edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator)1 Comparator (java.util.Comparator)1 Set (java.util.Set)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1