Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many threads do scala's parallel collections use by default?

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

Thanks

like image 553
Walrus the Cat Avatar asked Apr 18 '14 23:04

Walrus the Cat


1 Answers

Assuming there are no concurrently running processes and/or threads, meaning that all the CPU and cores are idle, this will be 1 thread per logical processor on the CPU. For example, if you have an Intel processor with 4 cores, but those cores have hyperthreading, then there will be 8 worker threads executing the parallel operation..

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

Be aware that the tabulate call in your example is not parallel - it is executed sequentially.

like image 145
axel22 Avatar answered Nov 06 '22 16:11

axel22