[Rcpp-devel] Apply Defined Rcpp Functions In Parallel
Dirk Eddelbuettel
edd at debian.org
Tue Aug 17 14:46:46 CEST 2021
Dillon,
The point of RMatrix and RVector in RcppParallel is to shield objects inside
the RcppParallel blocks using Intel TBB from any interaction with the outer R
process which may, or may not, run a gc() to rearrange its memory.
Where they work, you should not use Rcpp's own NumericMatrix and alike. As for
Is there a way to write generic functions that will work in both cases?
Yes, with care. Standard C++ should work. You have to 'arrange' functionality
in such a way that you have "clean" internal functions (using STL objects
and/or RMatrix and RVector) plus a wrapper making them callable from R).
Is it safe to create new objects on each thread
Yes, but they have to standard C++ objects. At the once, your sums or
reductions or ... have completed, converted to something you can return to R.
The golden rule simply is 'no R objects in the inner core'.
Hope this helps and was clear enough, I am still on my first coffee.
Dirk
--
https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list