[Rcpp-devel] Apply Defined Rcpp Functions In Parallel
Dillon Hammill
Dillon.Hammill at anu.edu.au
Tue Aug 17 21:19:22 CEST 2021
Thanks Dirk.
Please correct me if I am wrong, but does this mean that my Rcpp functions should be written using standard STL objects too - and I just include wrappers to handle conversion of the input and output to R objects?
What is the easiest way to perform this conversion (say for vector to RVector or vector of vectors to matrix)?
Thanks for your help.
Dillon
Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Dirk Eddelbuettel <edd at debian.org>
Sent: Tuesday, August 17, 2021 10:46:46 PM
To: Dillon Hammill <Dillon.Hammill at anu.edu.au>
Cc: rcpp-devel at lists.r-forge.r-project.org <rcpp-devel at lists.r-forge.r-project.org>
Subject: Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20210817/9bc2ae0d/attachment.html>
More information about the Rcpp-devel
mailing list