The Benefits of Multithreaded Performance with Microsoft R Open · MRAN Skip to main content

The Benefits of Multithreaded Performance with Microsoft R Open

Introduction

From its inception, R was designed to use only a single thread (processor) at a time. Even today, R works that way unless linked with multi-threaded BLAS/LAPACK libraries.

The multi-core machines of today offer parallel processing power. To take advantage of this, Microsoft R Open provides optional multi-threaded math libraries.

These libraries make it possible for so many common R operations to use all of the processing power available. Matrix operations, most notably, can compute in parallel with all available processing power to significantly reduce computation times.

When installed along with Microsoft R Open, they automatically use all available cores and processors to significantly reduce computation times — without the need to change a line of your R code. There's nothing special any package needs to do to benefit from these libraries either. In fact, any package used for vector/matrix operations will experience enhanced performance automatically when these libraries are installed.

Performance Benchmarks

Our tests show that linking to MKL on Windows and Linux platforms improves the performance of your R code, especially where many vector/matrix operations are used. Performance improves with additional cores, meaning you can expect better results on a four-core laptop than on a two-core laptop—even on non-Intel hardware.

Compared to open source R, the MKL offers significant performance gains, particularly on Windows.

To reproduce these results or understand the tests a bit more, visit https://github.com/andrie/version.compare.

Elapsed Time

Elapsed Time (Table)
Elapsed Time (Chart)

Relative Performance

Relative Performance (Table)
Relative Performance (Chart)

Multithreading on Windows

On Windows platforms, Microsoft R Open users can enable multi-threaded performance by:

  1. Downloading the optional, custom Intel Math Kernel Library (MKL) for Windows
  2. Installing that library as described.

This MKL library provides the BLAS and LAPACK library functions used by R. This library will install the custom RevoUtilsMath package into the default search path.

MKL's default behavior is to use as many parallel threads as there are available cores. There’s nothing you need to do to benefit from this performance improvement—not a single change to your R script is required. However, you can set a specific number of threads if you choose. Learn how...

Multithreading on Linux

On Linux platforms, Microsoft R Open users can enable multi-threaded performance by:

  1. Downloading the optional, custom Intel Math Kernel Library (MKL) for Linux
  2. Installing that library as described.

Note: This library will install the custom RevoUtilsMath package into the default search path.

This MKL library provides the BLAS and LAPACK library functions used by R. This library will install the custom RevoUtilsMath package into the default search path.

MKL's default behavior is to use as many parallel threads as there are available cores. There’s nothing you need to do to benefit from this performance improvement—not a single change to your R script is required. However, you can set a specific number of threads if you choose. Learn how...

Multithreading on Mac

On Mac OS X platforms, Microsoft R Open is pre-cofigured for multi-threaded performance using the Mac Accelerate Framework. There’s nothing you need to do to benefit from this performance improvement.

Controlling Threads

By default, MKL is configured to use as many parallel threads as there are available cores.

However, you can still control or restrict the number of threads using the setMKLthreads function from the RevoUtilsMath package installed along with the custom MKL.

For example, you might want to limit the number of threads to reserve some of the processing capacity for other activities, or if you’re doing explicit parallel programming with R packages such as foreach or other parallel programming tools.

Here's how:

setMKLthreads(<value>)

   Where the <value> is the maximum number of parallel threads, not to exceed the number of available cores.

Similarly, you can check the number of threads using:

getMKLthreads()