Published by the Foundation for Open Access Statistics Editors-in-chief: Bettina Grün, Torsten Hothorn, Rebecca Killick, Edzer Pebesma, Achim Zeileis    ISSN 1548-7660; CODEN JSSOBK
Authors: Thomas Nagler
Title: R-Friendly Multi-Threading in C++
Abstract: Calling multi-threaded C++ code from R has its perils. Since the R interpreter is single-threaded, one must not check for user interruptions or print to the R console from multiple threads. One can, however, synchronize with R from the main thread. The R package RcppThread (current version 1.0.0) contains a header only C++ library for thread safe communication with R that exploits this fact. It includes C++ classes for threads, a thread pool, and parallel loops that routinely synchronize with R. This article explains the package's functionality and gives examples of its usage. The synchronization mechanism may also apply to other threading frameworks. Benchmarks suggest that, although synchronization causes overhead, the parallel abstractions of RcppThread are competitive with other popular libraries in typical scenarios encountered in statistical computing.

Page views:: 1872. Submitted: 2018-11-03. Published: 2021-02-03.
Paper: R-Friendly Multi-Threading in C++     Download PDF (Downloads: 693)
RcppThread_1.0.0.tar.gz: R source package Download (Downloads: 41; 151KB)
v97c01.R: R replication code Download (Downloads: 61; 5KB)
v97c01-benchmarks.R: R replication code Download (Downloads: 57; 11KB)

DOI: 10.18637/jss.v097.c01

This work is licensed under the licenses
Paper: Creative Commons Attribution 3.0 Unported License
Code: GNU General Public License (at least one of version 2 or version 3) or a GPL-compatible license.