0
votes

I am converting some Matlab codes to Scala. In Matlab, there is the matlabpool function that is used to define the number of cores to use and "open" the core for parallel computations (and thereafter use for instance parfor instead of for to run loops in parallel).

matlabpool open 4

("opens" 4 cores)

matlabpool close

("closes" the cores for parallel processing)

What is the equivalent of matlabpool in Scala?

1

1 Answers

0
votes

The Scala compiler generates regular JVM bytecode, so in runtime Scala code has the same capabilities that Java code does. The JVM provides parallelism through light-weight threads (see Thread class and Runnable interface), which will use as many cores as they can (no more than one per thread, off course). See: Is Multi-Threaded algorithm required to make use of Multi-core processors?

Twitter's Scala School has a concurrency page (http://twitter.github.io/scala_school/concurrency.html) which indeed shows how to use Java concurrency primitives from Scala.

That said, there are facilities for parallel collections in Scala, which leverage the fork/join Java capabilities from JVM 6 onwards. See: http://docs.scala-lang.org/overviews/parallel-collections/overview.html