Questions tagged [parallel-collections]
50 questions
22
votes
2 answers
Will Scala's parallel collections guarantee ordering?
If I have this:
val a = Array(...)
and I write
a.par.map(e => someFunc(e))
Will the resulting collection be in the same order as the non-parallel collection?

Senthess
- 17,020
- 5
- 23
- 28
22
votes
1 answer
Missing import scala.collection.parallel in Scala 2.13
Parallel collections in Scala 2.12 were importable out-of-the-box like so
import scala.collection.parallel.immutable.ParVector
val pv = new ParVector[Int]
however why in Scala 2.13 package scala.collection.parallel seems to be missing?

Mario Galic
- 47,285
- 6
- 56
- 98
21
votes
2 answers
Parallel map operations?
Does Scala provide a way to execute parallel map operations as part of the standard language?
For example, given:
scala> val a = List((1,2), (3,4), (3,6))
a: List[(Int, Int)] = List((1,2), (3,4), (3,6))
I can do:
scala> a.map(tup => tup._1 +…

csvan
- 8,782
- 12
- 48
- 91
20
votes
1 answer
Can views be used with parallel collections?
The idiom for finding a result within a mapping of a collection goes something like this:
list.view.map(f).find(p)
where list is a List[A], f is an A => B, and p is a B => Boolean.
Is it possible to use view with parallel collections? I ask because…

Luigi Plinge
- 50,650
- 20
- 113
- 180
19
votes
2 answers
How do I replace the fork join pool for a Scala 2.9 parallel collection?
I've been looking at the new Scala 2.9 parallel collections and am hoping to abandon a whole lot of my crufty amateur versions of similar things. In particular, I'd like to replace the fork join pool which underlies the default implementation with…

Scott Morrison
- 3,100
- 24
- 39
12
votes
3 answers
When a ConcurrentBag is better than a List?
I am using a Parallel.Foreach for populating an external ConcurrentBag. I tried also to use a common List and everything works fine.
I have been lucky or I missed the special scope of ConcurrentBag?

ab_732
- 3,639
- 6
- 45
- 61
12
votes
2 answers
Is it a good idea to run `...par.map(` on large lists directly?
Let's say I have a somewhat large (several millions of items, or so) list of strings. Is it a good idea to run something like this:
val updatedList = myList.par.map(someAction).toList
Or would it be a better idea to group the list before running…

Vilius Normantas
- 3,708
- 6
- 25
- 38
10
votes
3 answers
Filtering Scala's Parallel Collections with early abort when desired number of results found
Given a very large instance of collection.parallel.mutable.ParHashMap (or any other parallel collection), how can one abort a filtering parallel scan once a given, say 50, number of matches has been found ?
Attempting to accumulate intermediate…

Alex Kravets
- 524
- 4
- 12
9
votes
2 answers
Understanding parallel exists and find
I take a List[Int] and want to search for a value x where x * 10 > 500 in parallel. So exists should return true if the list contains any value of 51 or greater.
def f(x: Int) = {
println("calculating for " + x)
Thread.sleep(100 - x)
…

Luigi Plinge
- 50,650
- 20
- 113
- 180
8
votes
1 answer
Constructing Scala parallel views with X.par.view vs X.view.par?
According to the paper on parallel collections and searching on the internet, parallel collections are supposed to work with views, but I am not clear on the difference…

Daniel Mahler
- 7,653
- 5
- 51
- 90
7
votes
1 answer
Why is this not faster using parallel collections?
I just wanted to test the parallel collections a bit and I used the following line of code (in REPL):
(1 to 100000).par.filter(BigInt(_).isProbablePrime(100))
against:
(1 to 100000).filter(BigInt(_).isProbablePrime(100))
But the parallel version…

Plankalkül
- 833
- 8
- 21
6
votes
3 answers
Transforming arrays in-place with parallel collections
When one has an array of objects it is often desirable (e.g. for performance reasons) to update (replace) some of the objects in place. For example, if you have an array of integers, you might want to replace the negative integers with positive…

Rex Kerr
- 166,841
- 26
- 322
- 407
6
votes
5 answers
Is this scala parallel array code threadsafe?
I want to use parallel arrays for a task, and before I start with the coding, I'd be interested in knowing if this small snipept is threadsafe:
import collection.mutable._
var listBuffer =…

Geo
- 93,257
- 117
- 344
- 520
6
votes
1 answer
Parallel collection processing of data larger than memory size
Is there a simple way to use scala parallel collections without loading a full collection into memory?
For example I have a large collection and I'd like to perform a particular operation (fold) in parallel only on a small chunk, that fits into…

Mikhail Golubtsov
- 6,285
- 3
- 29
- 36
5
votes
2 answers
How to create a Scala parallel collection from a Java collection
The easiest way to convert a Java Collection to a Scala equivalent is using JavaConversions, since Scala 2.8.. These implicit defs return wrappers for the contained Java Collection.
Scala 2.9 introduced parallel collections, where operations on a…

Dan Gravell
- 7,855
- 7
- 41
- 64