Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 109 lines (76 sloc) 4.022 kb
5749084 @axel22 Updated docs. No review.
axel22 authored
1 /* __ *\
2 ** ________ ___ / / ___ Scala API **
807dbe5 @heathermiller Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013
heathermiller authored
3 ** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
5749084 @axel22 Updated docs. No review.
axel22 authored
4 ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5 ** /____/\___/_/ |_/____/_/ | | **
6 ** |/ **
7 \* */
8
9
9923b97 @axel22 Moved parallel collections to library dir, chan...
axel22 authored
10 package scala.collection.parallel
11
12
13
6aca8a0 @axel22 Adding execution context based task support implementation.
axel22 authored
14 import java.util.concurrent.ThreadPoolExecutor
15 import scala.concurrent.forkjoin.ForkJoinPool
16 import scala.concurrent.ExecutionContext
9923b97 @axel22 Moved parallel collections to library dir, chan...
axel22 authored
17
18
19
f3e5454 @axel22 Make task support implementations public.
axel22 authored
20 /** A trait implementing the scheduling of
21 * a parallel collection operation.
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
22 *
23 * Parallel collections are modular in the way operations are scheduled. Each
24 * parallel collection is parametrized with a task support object which is
25 * responsible for scheduling and load-balancing tasks to processors.
f3e5454 @axel22 Make task support implementations public.
axel22 authored
26 *
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
27 * A task support object can be changed in a parallel collection after it has
28 * been created, but only during a quiescent period, i.e. while there are no
f3e5454 @axel22 Make task support implementations public.
axel22 authored
29 * concurrent invocations to parallel collection methods.
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
30 *
31 * There are currently a few task support implementations available for
32 * parallel collections. The [[scala.collection.parallel.ForkJoinTaskSupport]]
33 * uses a fork-join pool
34 * internally and is used by default on JVM 1.6 or greater. The less efficient
35 * [[scala.collection.parallel.ThreadPoolTaskSupport]] is a fallback for JVM
36 * 1.5 and JVMs that do not support the fork join pools. The
37 * [[scala.collection.parallel.ExecutionContextTaskSupport]] uses the
38 * default execution context implementation found in scala.concurrent, and it
39 * reuses the thread pool used in scala.concurrent (this is either a fork join
40 * pool or a thread pool executor, depending on the JVM version). The
41 * execution context task support is set to each parallel collection by
42 * default, so parallel collections reuse the same fork-join pool as the
43 * future API.
44 *
45 * Here is a way to change the task support of a parallel collection:
46 *
47 * {{{
48 * import scala.collection.parallel._
49 * val pc = mutable.ParArray(1, 2, 3)
50 * pc.tasksupport = new ForkJoinTaskSupport(
51 * new scala.concurrent.forkjoin.ForkJoinPool(2))
52 * }}}
53 *
54 * @see [[http://docs.scala-lang.org/overviews/parallel-collections/configuration.html Configuring Parallel Collections]] section
55 * on the parallel collection's guide for more information.
f3e5454 @axel22 Make task support implementations public.
axel22 authored
56 */
a730fb5 @axel22 Fixing jvm 1.5 support for parallel collections.
axel22 authored
57 trait TaskSupport extends Tasks
58
59
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
60 /** A task support that uses a fork join pool to schedule tasks.
61 *
62 * @see [[scala.collection.parallel.TaskSupport]] for more information.
63 */
f3e5454 @axel22 Make task support implementations public.
axel22 authored
64 class ForkJoinTaskSupport(val environment: ForkJoinPool = ForkJoinTasks.defaultForkJoinPool)
6aca8a0 @axel22 Adding execution context based task support implementation.
axel22 authored
65 extends TaskSupport with AdaptiveWorkStealingForkJoinTasks
66
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
67 /** A task support that uses a thread pool executor to schedule tasks.
68 *
69 * @see [[scala.collection.parallel.TaskSupport]] for more information.
70 */
f3e5454 @axel22 Make task support implementations public.
axel22 authored
71 class ThreadPoolTaskSupport(val environment: ThreadPoolExecutor = ThreadPoolTasks.defaultThreadPool)
6aca8a0 @axel22 Adding execution context based task support implementation.
axel22 authored
72 extends TaskSupport with AdaptiveWorkStealingThreadPoolTasks
73
74
f3e5454 @axel22 Make task support implementations public.
axel22 authored
75 /** A task support that uses an execution context to schedule tasks.
76 *
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
77 * It can be used with the default execution context implementation in the
78 * `scala.concurrent` package. It internally forwards the call to either a
79 * forkjoin based task support or a thread pool executor one, depending on
80 * what the execution context uses.
f3e5454 @axel22 Make task support implementations public.
axel22 authored
81 *
da8a29b @dcsobral SI-6032 Enhance TaskSupport documentation.
dcsobral authored
82 * By default, parallel collections are parametrized with this task support
83 * object, so parallel collections share the same execution context backend
84 * as the rest of the `scala.concurrent` package.
85 *
86 * @see [[scala.collection.parallel.TaskSupport]] for more information.
f3e5454 @axel22 Make task support implementations public.
axel22 authored
87 */
4496c5d @havocp Collection of updates to SIP-14 (scala.concurrent)
havocp authored
88 class ExecutionContextTaskSupport(val environment: ExecutionContext = scala.concurrent.ExecutionContext.global)
6aca8a0 @axel22 Adding execution context based task support implementation.
axel22 authored
89 extends TaskSupport with ExecutionContextTasks
90
9923b97 @axel22 Moved parallel collections to library dir, chan...
axel22 authored
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Something went wrong with that request. Please try again.