Search in sources :

Example 11 with ComputeCollectorFunc

use of edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc in project twister2 by DSC-SPIDAL.

the class ComputeCollectExample 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).setName("src");
    ComputeTSet<String> modify = src.direct().compute((ComputeCollectorFunc<Iterator<Integer>, String>) (input, collector) -> {
        while (input.hasNext()) {
            collector.collect(input.next() + "##");
        }
    }).setName("modify");
    modify.direct().forEach(data -> LOG.info("val: " + data));
}
Also used : BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) ComputeCollectorFunc(edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc)

Example 12 with ComputeCollectorFunc

use of edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc in project twister2 by DSC-SPIDAL.

the class AllReduceExample 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);
    LOG.info("test foreach");
    src.allReduce(Integer::sum).forEach(i -> LOG.info("foreach: " + i));
    LOG.info("test map");
    src.allReduce(Integer::sum).map(i -> i.toString() + "$$").direct().forEach(s -> LOG.info("map: " + s));
    LOG.info("test flat map");
    src.allReduce(Integer::sum).flatmap((i, c) -> c.collect(i.toString() + "$$")).direct().forEach(s -> LOG.info("flat:" + s));
    LOG.info("test compute");
    src.allReduce(Integer::sum).compute(i -> i * 2).direct().forEach(i -> LOG.info("comp: " + i));
    LOG.info("test computec");
    src.allReduce(Integer::sum).compute((ComputeCollectorFunc<Integer, String>) (input, output) -> output.collect("sum=" + input)).direct().forEach(s -> LOG.info("computec: " + s));
}
Also used : WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) TSetEnvironment(edu.iu.dsc.tws.tset.env.TSetEnvironment) ComputeCollectorFunc(edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc) SourceTSet(edu.iu.dsc.tws.tset.sets.batch.SourceTSet) 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) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment)

Aggregations

ComputeCollectorFunc (edu.iu.dsc.tws.api.tset.fn.ComputeCollectorFunc)12 BatchEnvironment (edu.iu.dsc.tws.tset.env.BatchEnvironment)12 JobConfig (edu.iu.dsc.tws.api.JobConfig)11 Config (edu.iu.dsc.tws.api.config.Config)11 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)11 ResourceAllocator (edu.iu.dsc.tws.rsched.core.ResourceAllocator)11 TSetEnvironment (edu.iu.dsc.tws.tset.env.TSetEnvironment)11 SourceTSet (edu.iu.dsc.tws.tset.sets.batch.SourceTSet)11 HashMap (java.util.HashMap)11 Logger (java.util.logging.Logger)11 ComputeFunc (edu.iu.dsc.tws.api.tset.fn.ComputeFunc)10 Iterator (java.util.Iterator)9 Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)8 SinkFunc (edu.iu.dsc.tws.api.tset.fn.SinkFunc)3 PrimitiveSchemas (edu.iu.dsc.tws.api.tset.schema.PrimitiveSchemas)3 SinkTSet (edu.iu.dsc.tws.tset.sets.batch.SinkTSet)3 ApplyFunc (edu.iu.dsc.tws.api.tset.fn.ApplyFunc)2 MapFunc (edu.iu.dsc.tws.api.tset.fn.MapFunc)2 LoadBalancePartitioner (edu.iu.dsc.tws.tset.fn.LoadBalancePartitioner)2 DirectTLink (edu.iu.dsc.tws.tset.links.batch.DirectTLink)1