Search in sources :

Example 6 with ReduceOperationFunction

use of edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction in project twister2 by DSC-SPIDAL.

the class BKeyedReduceExample method compute.

@Override
protected void compute(WorkerEnvironment workerEnv) {
    LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
    keyedReduce = new BKeyedReduce(workerEnv.getCommunicator(), logicalPlanBuilder, new ReduceOperationFunction(Op.SUM, MessageTypes.INTEGER_ARRAY), new FinalBulkReceiver(), MessageTypes.INTEGER, MessageTypes.INTEGER_ARRAY, 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.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);
            }
        }
        int[] reduced = GeneratorUtils.multiplyIntArray(ints, logicalPlanBuilder.getSources().size());
        List<Tuple<Integer, int[]>> expectedData = new ArrayList<>();
        for (Integer key : keysRoutedToThis) {
            expectedData.add(new Tuple<>(key, reduced));
        }
        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(), 1, tasksOfExecutor));
    // now initialize the workers
    for (int t : tasksOfExecutor) {
        // the map thread where data is produced
        Thread mapThread = new Thread(new KeyedBenchWorker.MapWorker(t));
        mapThread.start();
    }
}
Also used : SimpleKeyBasedSelector(edu.iu.dsc.tws.comms.selectors.SimpleKeyBasedSelector) IntArrayComparator(edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator) GeneratorUtils(edu.iu.dsc.tws.examples.verification.GeneratorUtils) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder) Config(edu.iu.dsc.tws.api.config.Config) SimpleKeyBasedSelector(edu.iu.dsc.tws.comms.selectors.SimpleKeyBasedSelector) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) TupleComparator(edu.iu.dsc.tws.examples.verification.comparators.TupleComparator) KeyedBenchWorker(edu.iu.dsc.tws.examples.comms.KeyedBenchWorker) 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) BKeyedReduce(edu.iu.dsc.tws.comms.batch.BKeyedReduce) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) BulkReceiver(edu.iu.dsc.tws.api.comms.BulkReceiver) Iterator(java.util.Iterator) Set(java.util.Set) Timing(edu.iu.dsc.tws.examples.utils.bench.Timing) MessageTypes(edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes) Logger(java.util.logging.Logger) BenchmarkConstants(edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants) List(java.util.List) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) IteratorComparator(edu.iu.dsc.tws.examples.verification.comparators.IteratorComparator) IntComparator(edu.iu.dsc.tws.examples.verification.comparators.IntComparator) Comparator(java.util.Comparator) Collections(java.util.Collections) ReduceOperationFunction(edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction) KeyedBenchWorker(edu.iu.dsc.tws.examples.comms.KeyedBenchWorker) HashSet(java.util.HashSet) Set(java.util.Set) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder) BKeyedReduce(edu.iu.dsc.tws.comms.batch.BKeyedReduce) IteratorComparator(edu.iu.dsc.tws.examples.verification.comparators.IteratorComparator) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Example 7 with ReduceOperationFunction

use of edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction in project twister2 by DSC-SPIDAL.

the class SReduceExample method compute.

@Override
protected void compute(WorkerEnvironment workerEnv) {
    if (jobParameters.getTargets() != 1) {
        LOG.warning("Setting targets to 1. Found, " + jobParameters.getTargets());
        jobParameters.getTaskStages().set(1, 1);
    }
    LogicalPlanBuilder logicalPlanBuilder = LogicalPlanBuilder.plan(jobParameters.getSources(), jobParameters.getTargets(), workerEnv).withFairDistribution();
    // create the communication
    reduce = new SReduce(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;
    reduceDone = !logicalPlan.getLogicalIdsOfWorker(workerId).contains(logicalPlanBuilder.getTargets().iterator().next());
    // generating the expectedIterations results at the end
    this.resultsVerifier = new ResultsVerifier<>(inputDataArray, (array, args) -> {
        int sourcesCount = jobParameters.getTaskStages().get(0);
        int[] outArray = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            outArray[i] = array[i] * sourcesCount;
        }
        return outArray;
    }, 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();
    }
}
Also used : IntArrayComparator(edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator) TIMING_MESSAGE_RECV(edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants.TIMING_MESSAGE_RECV) SingularReceiver(edu.iu.dsc.tws.api.comms.SingularReceiver) SReduce(edu.iu.dsc.tws.comms.stream.SReduce) 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) TIMING_ALL_RECV(edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants.TIMING_ALL_RECV) 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) ReduceOperationFunction(edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction) SReduce(edu.iu.dsc.tws.comms.stream.SReduce) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder)

Aggregations

ReduceOperationFunction (edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction)7 LogicalPlanBuilder (edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder)6 Op (edu.iu.dsc.tws.api.comms.Op)5 MessageTypes (edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes)5 Config (edu.iu.dsc.tws.api.config.Config)5 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)5 BenchmarkUtils (edu.iu.dsc.tws.examples.utils.bench.BenchmarkUtils)5 Timing (edu.iu.dsc.tws.examples.utils.bench.Timing)5 ResultsVerifier (edu.iu.dsc.tws.examples.verification.ResultsVerifier)5 IntArrayComparator (edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator)5 Set (java.util.Set)5 Logger (java.util.logging.Logger)5 SingularReceiver (edu.iu.dsc.tws.api.comms.SingularReceiver)4 BenchWorker (edu.iu.dsc.tws.examples.comms.BenchWorker)4 GeneratorUtils (edu.iu.dsc.tws.examples.verification.GeneratorUtils)4 BenchmarkConstants (edu.iu.dsc.tws.examples.utils.bench.BenchmarkConstants)3 Comparator (java.util.Comparator)3 Level (java.util.logging.Level)3 BReduce (edu.iu.dsc.tws.comms.batch.BReduce)2 SimpleKeyBasedSelector (edu.iu.dsc.tws.comms.selectors.SimpleKeyBasedSelector)2