The setParallelism
method sets the recommended number of parallel workers that fork/join pool of the parallel collection is supposed to use. Those K
workers may work on any part of the collection - it is up to the scheduler to decide which elements the workers will be assigned to.
If you would like to include only first K
elements in the parallel operation, you should use the take
method, followed by a map
:
myArray.par.take(K).map(...)
You can alternatively use view.take(K).map(...).force
to create a parallel view before doing the mapping.