Fork/Join Framework。そしてLambdaへ。
Upcoming SlideShare
Loading in...5
×
 

Fork/Join Framework。そしてLambdaへ。

on

  • 6,492 views

 

Statistics

Views

Total Views
6,492
Views on SlideShare
3,630
Embed Views
2,862

Actions

Likes
3
Downloads
31
Comments
0

7 Embeds 2,862

http://d.hatena.ne.jp 2098
http://www.javainthebox.com 747
https://twitter.com 6
url_unknown 4
http://webcache.googleusercontent.com 3
http://twitter.com 2
http://hatenatunnel.appspot.com 2
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Fork/Join Framework。そしてLambdaへ。 Fork/Join Framework。そしてLambdaへ。 Presentation Transcript

  • Fork/Join Framework。 そして Lambda へ。 Java in the Box 櫻庭 祐一
  • Java には信頼性の高い並行プログラムを構築するのに使える 構成要素がある Java: The Good Parts 10 章より引用
  • 1994 Java 1.0α Thread Runnable2004 J2SE 5.0 JSR 166 Concurrency Utilities
  • 1994 Java 1.0α Thread Concurrent Runnable2004 J2SE 5.0 JSR 166 Concurrency Utilities Parallel
  • トランジスタ数 周波数 消費電力
  • トランジスタ数 周波数 消費電力
  • 2004 UltraSPARC IV2006 Core2 Extream2009 Nehalem-EX2010 Opteron 61002010 SPARC T3Intel SCC
  • SingleCore 時代の SoftwareMultiCore 時代の Software
  • JSR166 Executor 同期Core 1Core 2Core 3Core 4
  • JSR166y Fork/Join Framework 同期Core 1Core 2Core 3Core 4
  • 分割統治法
  • 分割統治法フィボナッチ数列 F0 = 0, F1 = 1 Fn = Fn-1+ Fn-2 public int compute(int n) { if (n <= 1) { return n; } return compute(n-1) + compute(n-2); }
  • 分割統治法フィボナッチ数列 F0 = 0, F1 = 1 Fn = Fn-1+ Fn-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 Task 両端キュー DequeWorker1 Comp Fork Comp ForkWorker2 Comp Fork Comp Fork ソート 検索 数値計算 行列操作 枝狩り et al.
  • 内部イテレータ Java List<Integer> numbers = ...; for (int i = 0; i < numbers.size(); i++) { numbers.set(i, numbers.get(i) * 2); } Groovy def numbers = ... 独立 numbers.collect { it * 2 } 並行処理可
  • 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});
  • Multicore Era Thread/Executor JSR 166y Fork/Join FrameworkWork Stealing extra166y 内部イテレータJSR 335 もっと簡単に!Project Lambda
  • Tips 時間のかかる処理はしない キャッシュを考慮する 参考 ITpro Java SE 7 徹底理解 No.2 細粒度の並行処理 - Fork/Join FrameworkNo.3 Fork/Join Framework から Project Lambda へ
  • Fork/Join Framework。 そして Lambda へ。 Java in the Box 櫻庭 祐一