Fork/Join Framework。そしてLambdaへ。
-
Upload
skrb -
Category
Technology
-
view
6.682 -
download
3
description
Transcript of Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。
Java in the Box
そして Lambda へ。
櫻庭 祐一
Java には信頼性の高い
Java: The Good Parts
10章より引用
並行プログラムを構築するのに使える
構成要素がある
1994 Java 1.0α ThreadRunnable
2004 J2SE 5.0 JSR 166Concurrency Utilities
1994 Java 1.0α ThreadRunnable
2004 J2SE 5.0 JSR 166Concurrency Utilities
Concurrent
Parallel
トランジスタ数
周波数 消費電力
トランジスタ数
周波数 消費電力
2004 UltraSPARC IV
2006 Core2 Extream
2009 Nehalem-EX
2010 Opteron 6100
2010 SPARC T3
Intel SCC
SingleCore 時代の Software
MultiCore 時代の Software
JSR166 Executor
Core 1
Core 2
Core 3
Core 4
同期
JSR166y Fork/Join Framework
Core 1
Core 2
Core 3
Core 4
同期
分割統治法
分割統治法
フィボナッチ数列 F = 0, F = 1F = F + F
0 1n n-1 n-2
public int compute(int n) { if (n <= 1) { return n; } return compute(n-1) + compute(n-2); }
分割統治法
フィボナッチ数列 F = 0, F = 1F = F + F
0 1n n-1 n-2
class FibonacciTask extends RecursiveTask<Integer> { private final int n; FibonacciTask(int n) { this.n = n; } protected Integer compute() { if (n <= 1) { return n; } FibonacciTask f1 = new FibonacciTask(n - 1); f1.fork(); FibonacciTask f2 = new FibonacciTask(n - 2); return f2.compute() + f1.join(); }}
Work Stealing
Worker1
Worker2
両端キュー DequeTask
ForkComp
ForkComp
ForkComp
ForkComp
ソート 検索数値計算行列操作枝狩り et al.
内部イテレータ
List<Integer> numbers = ...; for (int i = 0; i < numbers.size(); i++) { numbers.set(i, numbers.get(i) * 2);}
Java
def numbers = ... numbers.collect { it * 2 }
Groovy
独立並行処理可
extra166y ParallelArray
Integer[] numbers = ...;ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array = ParallelArray.createFromCopy(numbers, pool); Ops.Op<Integer, Integer> doubler = new Ops.Op<>() { @Override public Integer op(Integer x) { return x * 2; }}; array.withMapping(doubler);
extra166y ParallelArray
Integer[] numbers = ...;ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array = ParallelArray.createFromCopy(numbers, pool); Ops.Op<Integer, Integer> doubler = new Ops.Op<>() { @Override public Integer op(Integer x) { return x * 2; }}; array.withMapping(doubler);
extra166y ParallelArray
Integer[] numbers = ...;ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array = ParallelArray.createFromCopy(numbers, pool); Ops.Op<Integer, Integer> doubler = #{Integer num -> num * 2}; array.withMapping(doubler); ラムダ式
Project Lambda
extra166y ParallelArray
Integer[] numbers = ...;ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array = ParallelArray.createFromCopy(numbers, pool); Ops.Op<Integer, Integer> doubler = #{Integer num -> num * 2}; array.withMapping(doubler); ラムダ式
Project Lambda
extra166y ParallelArray
Integer[] numbers = ...;ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array = ParallelArray.createFromCopy(numbers, pool); array.withMapping(#{Integer num -> num * 2});
Thread/ExecutorMulticore Era
JSR 166yFork/Join FrameworkJSR 166yFork/Join Framework
Work Stealing
内部イテレータextra166y
もっと簡単に!JSR 335Project LambdaJSR 335Project Lambda
Tips
時間のかかる処理はしない
キャッシュを考慮する
参考 ITpro Java SE 7 徹底理解
No.2 細粒度の並行処理 - Fork/Join Framework
No.3 Fork/Join Framework から Project Lambda へ
Fork/Join Framework。
Java in the Box
そして Lambda へ。
櫻庭 祐一