Successfully reported this slideshow.

JDK8 : parallel programming made (too ?) easy

6,444 views

Published on

Published in: Education
  • Be the first to comment

JDK8 : parallel programming made (too ?) easy

  1. 1. What did happen in 2005 ?
  2. 2. What did happen in 2005 ?
  3. 3. What did happen in 2005 ?
  4. 4. From 2005 till…
  5. 5. From 2005 till…
  6. 6. Java parallel toolbox
  7. 7. What is the Fork / Join about ?
  8. 8. Fork / Join caveats
  9. 9. Fork / Join caveats
  10. 10. Then comes the Parallel Arrays API http://g.oswego.edu/dl/concurrency-interest/
  11. 11. Then comes the Parallel Arrays API ForkJoinPool pool = new ForkJoinPool() ; // package ! ParralelLongArray a = ParralelLongArray.create(pool) ;
  12. 12. Then comes the Parallel Arrays API Ops.LongOp add2 = new Ops.LongOp() { @Override public long op(long l1) { return l1 + 2 ; } } ; a2 = a.withMapping(add2) ;
  13. 13. Then comes the Parallel Arrays API Ops.LongPredicate filter = new Ops.LongPredicate() { @Override public boolean op(long l1) { return l1 > 50 ; } } a2 = a.withFilter(filter) ; a2.all() ;
  14. 14. Then comes the Parallel Arrays API Ops.LongReducer reducer = new Ops.LongReducer() { @Override public long op(long l1, long l2) { return l1 + l2 ; } } long reducedValue = a.reduce(reducer, 0L) ;
  15. 15. JDK 6 & 7 2 tools available : - Fork / Join - Parallel Arrays
  16. 16. And then comes the JDK 8 Collection<Person> persons = ... ; int maxAge = persons.stream().map(p -> p.getAge()).reduce(0, Math::max) ; Collection<Person> oldies = new ArrayList<>() ; persons.stream().filter(p -> p.age > 40).into(oldies) ;
  17. 17. And then comes the JDK 8 Collection<Person> persons = ... ; int maxAge = persons.stream().parallel() .map(p -> p.getAge()).reduce(0, Math::max) ; Collection<Person> oldies = new ArrayList<>() ; persons.stream().parallel().filter(p -> p.age > 40).into(oldies) ;
  18. 18. And then comes the JDK 8 public interface Spliterator<E> { public Spliterator<E>[] splits() ; public int getNaturalSplits() ; } http://www.parleys.com/#st=5&id=3125&sl=0
  19. 19. How to use all that ?
  20. 20. 1st caveat : associativity
  21. 21. Associativity
  22. 22. Associativity
  23. 23. Associativity
  24. 24. 2nd caveat : performance long begin = System.nanoTime() ; List<String> hugeList = new ArrayList<>(N) ; // N = 16_000_000 for (int i = 0 ; i < N ; i++) { long l = random.nextLong() ; l = l > 0 ? l : -l ; hugeList.add(Long.toString(l, 32)) ; }
  25. 25. Sorting
  26. 26. Sorting performance
  27. 27. Sorting performance
  28. 28. Sorting performance
  29. 29. Sorting performance
  30. 30. Sorting performance
  31. 31. Sorting performance
  32. 32. Sorting performance
  33. 33. Sorting performance
  34. 34. Sorting performance
  35. 35. An even worse case
  36. 36. An even worse case
  37. 37. An even worse case
  38. 38. Arrays ? Going parallel is easy !
  39. 39. Arrays ? Going parallel is easy…
  40. 40. Arrays ? Going parallel is easy…
  41. 41. 3rd caveat
  42. 42. 3rd caveat
  43. 43. Conclusion
  44. 44. Conclusion
  45. 45. Conclusion
  46. 46. Conclusion
  47. 47. Conclusion
  48. 48. Thank you !
  49. 49. Q&A
  50. 50. Downloads

×