Why doesn't this happen faster using parallel collections?

I just need to check out 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 is not faster. In fact, it even feels a little slower (but I did not).

Is there any explanation for this?

Edit 1: Yes, I have a multi-core processor

Edit 2: Ok, I myself "solved" the problem. The implementation of isProbablePrime seems to be a problem, not parallel collections. I replaced isProbablePrime with another function to test for simplicity, and now I get the expected acceleration.

+7
source share
1 answer

Both with serial and parallel filter ranges will generate a vector data structure - a Vector or ParVector respectively.

This is a known problem with parallel vectors that are generated from sets of ranges - transformer methods (such as filter ) for parallel vectors do not build the vector in parallel.

A solution for this, which provides an efficient parallel construction of vectors, has already been developed, but not yet implemented. I suggest you record a ticket so that it can be fixed for the next version.

+6
source

All Articles