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));
}
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));
}
Aggregations