multithreading with R?

R

R Problem Overview


Reading the R-project website, there are some (unclear) references to multithreading with R, but it is unclear how the base product and CRAN libraries are compiled.

Revolution Analytics offers multithreaded base(?) download for Windows and Redhat.

Would some of the other Linux distributions also include multithreaded R (and packages)?

R Solutions


Solution 1 - R

You are confused.

The R (and before it, S) internals are single-threaded, and will almost surely remain single-threaded. As I understand it, Duncan Temple Lang's PhD work was about overcoming this, and if he can't do it...

That said, there are pockets of multi-threadedness:

  • First off, whenever you make external calls, and with proper locking, you can go multi-threaded. That is what the BLAS libraries MKL, Goto/Open BLAS, Atlas (if built multithreaded), ... all offer. Revo R "merely" ships with (Intel's) MKL as Intel happens to be a key Revo investor

  • If you are careful about what you do, you can use OpenMP (a compiler extension for multi-threading). This started with Luke Tierney's work on pnmath and pnmath0 (which used to be experimental / external packages) and has since been coming into R itself, slowly but surely.

  • Next, in a multicore world, and on the right operating system, you can always fork(). That is what package multicore pioneered and which package parallel now carries on.

  • Last but not least there is the network / RPC route with MPI used by packages like Rmpi, snow, parallel, ... and covered in HPC introductions.

Solution 2 - R

Renjin is an JVM based implementation of the interpreter. They claim that:

> Unlike GNU R, Renjin is multithreaded and will run happily in a Platform-as-a-Service environment such as Google Appengine, AWS Elastic Beanstalk, Heroku or Microsoft Azure.

#resource http://www.bedatadriven.com/products/renjin.html

Still, the actual R packages we would call from R may not be thread safe.

See Jep documentation explaining this issue from standpoint of calling CPython from Java/Scala.

https://github.com/ninia/jep/wiki/How-Jep-Works#threading-complications

> Due to complications and limitations of JNI, a thread that creates a Jep instance must be reused for all method calls to that Jep instance. Jep will enforce this and throw exceptions mentioning invalid thread access. (In the future we hope to simplify or provide utilities for thread management). > > More than one Jep instance should not be run on the same thread at the same time. While this is technically allowed, it can potentially mess up the thread state and lead to deadlock in the Python interpreter. This will probably be changed to throw an exception if encountered in the future.

So, there seems to be hope with Renjin but actual binary (C/C++, etc) packages used need to be verified for thread safety.

There are other R implementations

https://dynamicecology.wordpress.com/2014/01/14/r-isnt-just-r-anymore/

Solution 3 - R

What about this? Since the modification date of that page is in May 2014, I think the mentioned packages are relatively new, or maybe those haven't been stable at the time the first answer has been written.

Solution 4 - R

You can effectively multi-thread R by using KNIME or any other program that utilizes the rserve.exe executable. In KNIME, you can put an R Snippet within a Parallel Chunk node series for operations done row-wise. For column-wise operations, you can split the data set into subsets of columns and execute R Snippets on each set, then merge them back together.

I hope this makes your CPU fan spin faster!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongliptakView Question on Stackoverflow
Solution 1 - RDirk EddelbuettelView Answer on Stackoverflow
Solution 2 - RSemanticBeengView Answer on Stackoverflow
Solution 3 - RJavadView Answer on Stackoverflow
Solution 4 - REvan BristowView Answer on Stackoverflow