Skip to content

RcppCore/RcppParallel

 
 

Repository files navigation

RcppParallel Package

High level functions for doing parallel programming with Rcpp. For example, the parallelFor function can be used to convert the work of a standard serial "for" loop into a parallel one and the parallelReduce function can be used for accumulating aggregate or other values.

The high level interface enables safe and robust parallel programming without direct manipulation of operating system threads. On Windows, OS X, and Linux systems the underlying implementation is based on Intel TBB (Threading Building Blocks). On other platforms a less-performant fallback implementation based on the TinyThread library is used.

Examples

Here are links to some examples that illustrate using RcppParallel. Performance benchmarks were executed on a 2.6GHz Haswell MacBook Pro with 4 cores (8 with hyperthreading).

Parallel Matrix Transform --- Demonstrates using parallelFor to transform a matrix (take the square root of each element) in parallel. In this example the parallel version performs about 2.5x faster than the serial version.

Parallel Vector Sum --- Demonstrates using parallelReduce to take the sum of a vector in parallel. In this example the parallel version performs 4.5x faster than the serial version.

Parallel Distance Matrix --- Demonstrates using parallelFor to compute pairwise distances for each row in an input data matrix. In this example the parallel version performs 5.5x faster than the serial version.

Parallel Inner Product --- Demonstrates using parallelReduce to compute the inner product of two vectors in parallel. In this example the parallel version performs 2.5x faster than the serial version.

Usage

You can install the RcppParallel package from CRAN as follows:

install.packages("RcppParallel")

sourceCpp

You can use the RcppParallel library from within a standalone C++ source file as follows:

// [[Rcpp::depends(RcppParallel)]]
#include <RcppParallel.h>

Packages

If you want to use RcppParallel from within an R package you add the following to your DESCRIPTION file:

Imports: RcppParallel
LinkingTo: RcppParallel

And the following to your NAMESPACE file:

importFrom(RcppParallel, RcppParallelLibs)

Finally, for Windows builds you'll need the following in src\Makevars.win to ensure that your package can link against the TBB DLL:

PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" \
              -e "RcppParallel::RcppParallelLibs()")

License

The RcppParallel package is made available under the GPLv2.

The TinyThread library is licensed under the zlib/libpng license as described here.

The Intel TBB Library is licensed under the GPLv2 (as described at https://www.threadingbuildingblocks.org/Licensing):

TBB and other open-source software available from this site is licensed under GPLv2 with the (libstdc++) runtime exception. Specifically, the TBB open-source license is the same license used by the GNU libstdc++ library in gcc 4.2.1 (and earlier). For a complete description of the license, please visit the official GNU website for GPLv2 and for the runtime exception.

Runtime Exception

As a special exception, you may use this file as part of a free software
library without restriction.  Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License.  This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.

About

High-level functions for parallel programming with Rcpp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published