How many threads does scala use by default in parallel collections?

When I call Array.tabulate(100)(i=>i).par map { _+ 1}how many threads are used?

thank

+4
source share
3 answers

Assuming that processes and / or threads are not running at the same time, which means that all CPUs and cores are inactive, this will be 1 thread for each logical processor on the processor. For example, if you have an Intel processor with 4 cores, but these cores have hyperthreading, then 8 worker threads will be executed, performing a parallel operation.

In any case, this is the same value returned by the method availableProcessorsin the JDK.

, tabulate - .

+4

scala ForkJoinThreadPool, java. :

 public ForkJoinPool() {
        this(Math.min(MAX_CAP, Runtime.getRuntime().availableProcessors()),
             defaultForkJoinWorkerThreadFactory, null, false);
    }
+1

According to this post's comment , 1 thread per core is used by default.

0
source

Source: https://habr.com/ru/post/1537149/


All Articles