Search in sources :

Example 1 with BDirect

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

the class InputDataStreamer method execute.

@Override
protected void execute(WorkerEnvironment workerEnv) {
    List<Integer> sources = new ArrayList<>();
    List<Integer> targets = new ArrayList<>();
    Integer noOfSourceTasks = taskStages.get(0);
    for (int i = 0; i < noOfSourceTasks; i++) {
        sources.add(i);
    }
    Integer noOfTargetTasks = taskStages.get(1);
    for (int i = 0; i < noOfTargetTasks; i++) {
        targets.add(noOfSourceTasks + i);
    }
    direct = new BDirect(workerEnv.getCommunicator(), logicalPlan, sources, targets, new DirectReceiver(), MessageTypes.DOUBLE);
    Set<Integer> tasksOfExecutor = Utils.getTasksOfExecutor(workerId, logicalPlan, taskStages, 0);
    for (int t : tasksOfExecutor) {
        finishedSources.put(t, false);
    }
    if (tasksOfExecutor.size() == 0) {
        sourcesDone = true;
    }
    for (int t : tasksOfExecutor) {
        Thread mapThread = new Thread(new DataStreamer(t));
        mapThread.start();
    }
}
Also used : ArrayList(java.util.ArrayList) BDirect(edu.iu.dsc.tws.comms.batch.BDirect)

Example 2 with BDirect

use of edu.iu.dsc.tws.comms.batch.BDirect 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();
    }
}
Also used : IntStream(java.util.stream.IntStream) IntArrayComparator(edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator) BulkReceiver(edu.iu.dsc.tws.api.comms.BulkReceiver) Iterator(java.util.Iterator) BDirect(edu.iu.dsc.tws.comms.batch.BDirect) 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) ArrayList(java.util.ArrayList) List(java.util.List) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) IteratorComparator(edu.iu.dsc.tws.examples.verification.comparators.IteratorComparator) BenchmarkUtils(edu.iu.dsc.tws.examples.utils.bench.BenchmarkUtils) ResultsVerifier(edu.iu.dsc.tws.examples.verification.ResultsVerifier) Comparator(java.util.Comparator) LogicalPlanBuilder(edu.iu.dsc.tws.comms.utils.LogicalPlanBuilder) BDirect(edu.iu.dsc.tws.comms.batch.BDirect) BenchWorker(edu.iu.dsc.tws.examples.comms.BenchWorker) IteratorComparator(edu.iu.dsc.tws.examples.verification.comparators.IteratorComparator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BDirect (edu.iu.dsc.tws.comms.batch.BDirect)2 ArrayList (java.util.ArrayList)2 BulkReceiver (edu.iu.dsc.tws.api.comms.BulkReceiver)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 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 ResultsVerifier (edu.iu.dsc.tws.examples.verification.ResultsVerifier)1 IntArrayComparator (edu.iu.dsc.tws.examples.verification.comparators.IntArrayComparator)1 IteratorComparator (edu.iu.dsc.tws.examples.verification.comparators.IteratorComparator)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1