Search in sources :

Example 1 with GatherTLink

use of edu.iu.dsc.tws.tset.links.batch.GatherTLink in project twister2 by DSC-SPIDAL.

the class TSetGatherExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    super.execute(workerEnv);
    BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
    // set the parallelism of source to task stage 0
    int srcPara = jobParameters.getTaskStages().get(0);
    int sinkPara = jobParameters.getTaskStages().get(1);
    SourceTSet<int[]> source = env.createSource(new TestBaseSource(), srcPara).setName("Source");
    GatherTLink<int[]> gather = source.gather();
    SinkTSet<Iterator<Tuple<Integer, int[]>>> sink = gather.sink((SinkFunc<Iterator<Tuple<Integer, int[]>>>) val -> {
        int[] value = null;
        while (val.hasNext()) {
            value = val.next().getValue();
        }
        experimentData.setOutput(value);
        LOG.info("Results " + Arrays.toString(value));
        try {
            verify(OperationNames.GATHER);
        } catch (VerificationException e) {
            LOG.info("Exception Message : " + e.getMessage());
        }
        return true;
    });
    env.run(sink);
}
Also used : Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Arrays(java.util.Arrays) Iterator(java.util.Iterator) SourceTSet(edu.iu.dsc.tws.tset.sets.batch.SourceTSet) VerificationException(edu.iu.dsc.tws.examples.verification.VerificationException) GatherTLink(edu.iu.dsc.tws.tset.links.batch.GatherTLink) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) SinkTSet(edu.iu.dsc.tws.tset.sets.batch.SinkTSet) OperationNames(edu.iu.dsc.tws.api.compute.OperationNames) BaseTSetBatchWorker(edu.iu.dsc.tws.examples.tset.BaseTSetBatchWorker) Logger(java.util.logging.Logger) SinkFunc(edu.iu.dsc.tws.api.tset.fn.SinkFunc) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) TSetEnvironment(edu.iu.dsc.tws.tset.env.TSetEnvironment) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) Iterator(java.util.Iterator) VerificationException(edu.iu.dsc.tws.examples.verification.VerificationException)

Example 2 with GatherTLink

use of edu.iu.dsc.tws.tset.links.batch.GatherTLink in project twister2 by DSC-SPIDAL.

the class GatherExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
    int start = env.getWorkerID() * 100;
    SourceTSet<Integer> src = dummySource(env, start, COUNT, PARALLELISM);
    GatherTLink<Integer> gather = src.gather();
    LOG.info("test foreach");
    gather.forEach(i -> LOG.info("foreach: " + i));
    LOG.info("test map");
    gather.map(i -> i.toString() + "$$").withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("map: " + s));
    LOG.info("test compute");
    gather.compute((ComputeFunc<Iterator<Tuple<Integer, Integer>>, String>) input -> {
        int sum = 0;
        while (input.hasNext()) {
            sum += input.next().getValue();
        }
        return "sum=" + sum;
    }).withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("compute: " + s));
    LOG.info("test computec");
    gather.compute((ComputeCollectorFunc<Iterator<Tuple<Integer, Integer>>, String>) (input, output) -> {
        int sum = 0;
        while (input.hasNext()) {
            sum += input.next().getValue();
        }
        output.collect("sum=" + sum);
    }).withSchema(PrimitiveSchemas.STRING).direct().forEach(s -> LOG.info("computec: " + s));
    gather.mapToTuple(i -> new Tuple<>(i % 2, i)).keyedDirect().forEach(i -> LOG.info("mapToTuple: " + i.toString()));
}
Also used : Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Iterator(java.util.Iterator) ComputeCollectorFunc(edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc) SourceTSet(edu.iu.dsc.tws.tset.sets.batch.SourceTSet) GatherTLink(edu.iu.dsc.tws.tset.links.batch.GatherTLink) ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) HashMap(java.util.HashMap) Config(edu.iu.dsc.tws.api.config.Config) Logger(java.util.logging.Logger) JobConfig(edu.iu.dsc.tws.api.JobConfig) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) TSetEnvironment(edu.iu.dsc.tws.tset.env.TSetEnvironment) ComputeFunc(edu.iu.dsc.tws.api.tset.fn.ComputeFunc) PrimitiveSchemas(edu.iu.dsc.tws.api.tset.schema.PrimitiveSchemas) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) ComputeCollectorFunc(edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc) ComputeFunc(edu.iu.dsc.tws.api.tset.fn.ComputeFunc) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Aggregations

Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)2 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)2 BatchEnvironment (edu.iu.dsc.tws.tset.env.BatchEnvironment)2 TSetEnvironment (edu.iu.dsc.tws.tset.env.TSetEnvironment)2 GatherTLink (edu.iu.dsc.tws.tset.links.batch.GatherTLink)2 SourceTSet (edu.iu.dsc.tws.tset.sets.batch.SourceTSet)2 Iterator (java.util.Iterator)2 Logger (java.util.logging.Logger)2 JobConfig (edu.iu.dsc.tws.api.JobConfig)1 OperationNames (edu.iu.dsc.tws.api.compute.OperationNames)1 Config (edu.iu.dsc.tws.api.config.Config)1 ComputeCollectorFunc (edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc)1 ComputeFunc (edu.iu.dsc.tws.api.tset.fn.ComputeFunc)1 SinkFunc (edu.iu.dsc.tws.api.tset.fn.SinkFunc)1 PrimitiveSchemas (edu.iu.dsc.tws.api.tset.schema.PrimitiveSchemas)1 BaseTSetBatchWorker (edu.iu.dsc.tws.examples.tset.BaseTSetBatchWorker)1 VerificationException (edu.iu.dsc.tws.examples.verification.VerificationException)1 ResourceAllocator (edu.iu.dsc.tws.rsched.core.ResourceAllocator)1 SinkTSet (edu.iu.dsc.tws.tset.sets.batch.SinkTSet)1 Arrays (java.util.Arrays)1