use of edu.iu.dsc.tws.tset.fn.LoadBalancePartitioner in project twister2 by DSC-SPIDAL.
the class PartitionExample 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.partition(new LoadBalancePartitioner<>()).forEach(i -> LOG.info("foreach: " + i));
LOG.info("test map");
src.partition(new LoadBalancePartitioner<>()).map(i -> i.toString() + "$$").direct().forEach(s -> LOG.info("map: " + s));
LOG.info("test flat map");
src.partition(new LoadBalancePartitioner<>()).flatmap((i, c) -> c.collect(i.toString() + "##")).direct().forEach(s -> LOG.info("flat:" + s));
LOG.info("test compute");
src.partition(new LoadBalancePartitioner<>()).compute((ComputeFunc<Iterator<Integer>, Integer>) input -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next();
}
return sum;
}).direct().forEach(i -> LOG.info("comp: " + i));
LOG.info("test computec");
src.partition(new LoadBalancePartitioner<>()).compute((ComputeCollectorFunc<Iterator<Integer>, String>) (input, output) -> {
int sum = 0;
while (input.hasNext()) {
sum += input.next();
}
output.collect("sum" + sum);
}).direct().forEach(s -> LOG.info("computec: " + s));
}
use of edu.iu.dsc.tws.tset.fn.LoadBalancePartitioner in project twister2 by DSC-SPIDAL.
the class HelloTSet method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
LOG.info("Strating Hello TSet Example");
int para = env.getConfig().getIntegerValue("para", 4);
SourceTSet<int[]> source = env.createSource(new SourceFunc<int[]>() {
private int count = 0;
@Override
public boolean hasNext() {
return count < para;
}
@Override
public int[] next() {
count++;
return new int[] { 1, 1, 1 };
}
}, para).setName("source");
PartitionTLink<int[]> partitioned = source.partition(new LoadBalancePartitioner<>());
ComputeTSet<int[]> mapedPartition = partitioned.map((MapFunc<int[], int[]>) input -> Arrays.stream(input).map(a -> a * 2).toArray());
ReduceTLink<int[]> reduce = mapedPartition.reduce((t1, t2) -> {
int[] ret = new int[t1.length];
for (int i = 0; i < t1.length; i++) {
ret[i] = t1[i] + t2[i];
}
return ret;
});
SinkTSet<int[]> sink = reduce.sink(value -> {
LOG.info("Results " + Arrays.toString(value));
return false;
});
env.run(sink);
LOG.info("Ending Hello TSet Example");
}
use of edu.iu.dsc.tws.tset.fn.LoadBalancePartitioner in project twister2 by DSC-SPIDAL.
the class KPartitionExample 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);
KeyedPartitionTLink<Integer, Integer> klink = src.mapToTuple(i -> new Tuple<>(i % 10, i)).keyedPartition(new LoadBalancePartitioner<>());
LOG.info("test foreach");
klink.forEach(t -> LOG.info(t.getKey() + "_" + t.getValue()));
LOG.info("test map");
klink.map(i -> i.toString() + "$$").direct().forEach(s -> LOG.info("map: " + s));
LOG.info("test compute");
klink.compute((ComputeFunc<Iterator<Tuple<Integer, Integer>>, String>) input -> {
StringBuilder s = new StringBuilder();
while (input.hasNext()) {
s.append(input.next().toString()).append(" ");
}
return s.toString();
}).direct().forEach(s -> LOG.info("compute: concat " + s));
LOG.info("test computec");
klink.compute((ComputeCollectorFunc<Iterator<Tuple<Integer, Integer>>, String>) (input, output) -> {
while (input.hasNext()) {
output.collect(input.next().toString());
}
}).direct().forEach(s -> LOG.info("computec: " + s));
}
Aggregations