Search in sources :

Example 1 with BKeyedReduce

use of edu.iu.dsc.tws.comms.batch.BKeyedReduce in project twister2 by DSC-SPIDAL.

the class WordCountWorker method execute.

@Override
public void execute(WorkerEnvironment wEnv) {
    this.workerEnv = wEnv;
    this.workerId = workerEnv.getWorkerId();
    taskStages.add(NO_OF_TASKS);
    taskStages.add(NO_OF_TASKS);
    // lets create the task plan
    this.logicalPlan = Utils.createStageLogicalPlan(workerEnv, taskStages);
    setupTasks();
    // create the communication
    wordAggregator = new WordAggregator();
    keyGather = new BKeyedReduce(workerEnv.getCommunicator(), logicalPlan, sources, destinations, new ReduceFunction() {

        @Override
        public void init(Config cfg, DataFlowOperation op, Map<Integer, List<Integer>> expectedIds) {
        }

        @Override
        public Object reduce(Object t1, Object t2) {
            return (Integer) t1 + (Integer) t2;
        }
    }, wordAggregator, MessageTypes.OBJECT, MessageTypes.INTEGER, new HashingSelector());
    // assign the task ids to the workers, and run them using threads
    scheduleTasks();
    // progress the communication
    progress();
    // close communication
    workerEnv.close();
}
Also used : BKeyedReduce(edu.iu.dsc.tws.comms.batch.BKeyedReduce) Config(edu.iu.dsc.tws.api.config.Config) DataFlowOperation(edu.iu.dsc.tws.api.comms.DataFlowOperation) ReduceFunction(edu.iu.dsc.tws.api.comms.ReduceFunction) HashingSelector(edu.iu.dsc.tws.comms.selectors.HashingSelector) Map(java.util.Map)

Example 2 with BKeyedReduce

use of edu.iu.dsc.tws.comms.batch.BKeyedReduce 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)

Aggregations

Config (edu.iu.dsc.tws.api.config.Config)2 BKeyedReduce (edu.iu.dsc.tws.comms.batch.BKeyedReduce)2 BulkReceiver (edu.iu.dsc.tws.api.comms.BulkReceiver)1 DataFlowOperation (edu.iu.dsc.tws.api.comms.DataFlowOperation)1 Op (edu.iu.dsc.tws.api.comms.Op)1 ReduceFunction (edu.iu.dsc.tws.api.comms.ReduceFunction)1 MessageTypes (edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes)1 Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)1 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)1 ReduceOperationFunction (edu.iu.dsc.tws.comms.functions.reduction.ReduceOperationFunction)1 HashingSelector (edu.iu.dsc.tws.comms.selectors.HashingSelector)1 SimpleKeyBasedSelector (edu.iu.dsc.tws.comms.selectors.SimpleKeyBasedSelector)1 LogicalPlanBuilder (edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder)1 KeyedBenchWorker (edu.iu.dsc.tws.examples.comms.KeyedBenchWorker)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