1

I am using the par.map expression to execute processes in parallel in Scala (SBT).

Consider list.par.map(function(_)) (I am preparing an MWE). This means that function(_) should be applied to all the elements of the list in a parallel fashion. In my example, list has 3 elements. But Scala executes only function(list(1)) and function(list(2)) in parallel, and only afterwards function(list(3)).

Is there a reason for this behaviour? Is there a relation with the fact that the programme is executed on a two-core processor? Or how could you impose to execute all three things in parallel?

2

1 Answer 1

5

This question has been asked before:

and is well documented:

what you want is something like:

var parallelList = list.par
parallelList.tasksupport = new ForkJoinTaskSupport(
     new scala.concurrent.forkjoin.ForkJoinPool(parlevel))
parallelList.map(function(_))

That said if your running on a 2 core processor you only have two threads (unless the cores are hyper threaded of course) meaning you can't have more than 2 parallel operations at once.

Sign up to request clarification or add additional context in comments.

1 Comment

@Karlo are you satisfied with this answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.