List of usage examples for java.util.concurrent ForkJoinPool invoke
public <T> T invoke(ForkJoinTask<T> task)
From source file:Main.java
public static void main(String[] args) throws Exception { int size = 100000; int[] v1 = new int[size]; for (int i = 0; i < size; i++) { v1[i] = i;//from w ww. jav a 2 s . co m } for (SEQ_THRESHOLD = 10; SEQ_THRESHOLD < size; SEQ_THRESHOLD += 50) { double avgTime = 0.0; int samples = 5; for (int i = 0; i < samples; i++) { long startTime = System.nanoTime(); ForkJoinPool fjp = new ForkJoinPool(); fjp.invoke(new MyAction(0, size, v1)); long endTime = System.nanoTime(); double secsTaken = (endTime - startTime) / 1.0e9; avgTime += secsTaken; } System.out.println(SEQ_THRESHOLD + " " + (avgTime / samples)); } }
From source file:Test.java
public static void main(String[] args) { int numbers[] = new int[100000]; ForkJoinPool forkJoinPool = new ForkJoinPool(); long result = forkJoinPool.invoke(new SumOfSquaresTask(0, numbers.length)); System.out.println("forkJoinPool: " + forkJoinPool.toString()); System.out.println("forkJoinPool: " + forkJoinPool.toString()); System.out.println("Sum of squares: " + result); }
From source file:Main.java
public static void main(String[] args) { ForkJoinPool pool = new ForkJoinPool(); IntSum task = new IntSum(3); long sum = pool.invoke(task); System.out.println("Sum is " + sum); }
From source file:Main.java
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); long expectedSum = 0; for (int i = 0; i < 10000; i++) { int random = 1 + (int) (Math.random() * ((100 - 1) + 1)); list.add(random);/*from w w w. j a va2 s . c o m*/ expectedSum += random; } System.out.println("expected sum: " + expectedSum); ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors()); RecursiveSum recursiveSum = new RecursiveSum(list, 0, list.size()); long recSum = forkJoinPool.invoke(recursiveSum); System.out.println("recursive-sum: " + recSum); }
From source file:Main.java
public static void main(String[] args) { ForkJoinPool fjPool = new ForkJoinPool(); int[] a = new int[3333344]; for (int i = 0; i < a.length; i++) { int k = (int) (Math.random() * 22222); a[i] = k;/*from w w w .j ava 2 s . co m*/ } ForkJoinQuicksortTask forkJoinQuicksortTask = new ForkJoinQuicksortTask(a, 0, a.length - 1); long start = System.nanoTime(); fjPool.invoke(forkJoinQuicksortTask); System.out.println("Time: " + (System.nanoTime() - start)); }
From source file:org.caleydo.core.util.impute.KNNImpute.java
public static void main(String[] args) throws IOException { ImmutableList.Builder<Gene> b = ImmutableList.builder(); List<String> lines = CharStreams .readLines(new InputStreamReader(KNNImpute.class.getResourceAsStream("khan.csv"))); lines = lines.subList(1, lines.size()); int j = 0;/*from ww w . j a va 2s.co m*/ for (String line : lines) { String[] l = line.split(";"); float[] d = new float[l.length]; int nans = 0; for (int i = 0; i < l.length; ++i) { if ("NA".equals(l[i])) { nans++; d[i] = Float.NaN; } else { d[i] = Float.parseFloat(l[i]); } } b.add(new Gene(j++, nans, d)); } final KNNImputeDescription desc2 = new KNNImputeDescription(); desc2.setMaxp(100000); KNNImpute r = new KNNImpute(desc2, b.build()); ForkJoinPool p = new ForkJoinPool(); p.invoke(r); try (PrintWriter w = new PrintWriter("khan.imputed.csv")) { w.println(StringUtils.repeat("sample", ";", r.samples)); for (Gene g : r.genes) { float[] d = g.data; int nan = 0; w.print(Float.isNaN(d[0]) ? g.nanReplacements[nan++] : d[0]); for (int i = 1; i < d.length; ++i) w.append(';').append(String.valueOf(Float.isNaN(d[i]) ? g.nanReplacements[nan++] : d[i])); w.println(); } } }
From source file:org.diorite.utils.concurrent.ParallelUtils.java
public static <T> T realParallelStream(final Supplier<T> streamAction, final int parallelism) { final ForkJoinPool pool = new ForkJoinPool(parallelism); return pool.invoke(createTask(streamAction)); }
From source file:org.diorite.utils.concurrent.ParallelUtils.java
public static void realParallelStream(final Runnable streamAction, final int parallelism, final boolean await) { final ForkJoinPool pool = new ForkJoinPool(parallelism); if (await) {/* w w w . ja v a 2s . c o m*/ pool.invoke(createSimpleTask(streamAction)); } else { pool.submit(streamAction); } }
From source file:org.diorite.utils.concurrent.ParallelUtils.java
public static <T> T realParallelStream(final Supplier<T> streamAction, final int parallelism, final String name) { final ForkJoinPool pool = new ForkJoinPool(parallelism, new NamedForkJoinWorkerFactory(name), null, false); return pool.invoke(createTask(streamAction)); }
From source file:org.diorite.utils.concurrent.ParallelUtils.java
public static void realParallelStream(final Runnable streamAction, final int parallelism, final boolean await, final String name) { final ForkJoinPool pool = new ForkJoinPool(parallelism, new NamedForkJoinWorkerFactory(name), null, false); if (await) {//from w w w.j a va2s .c o m pool.invoke(createSimpleTask(streamAction)); } else { pool.submit(streamAction); } }