Apologies, I meant vector of vectors to RMatrix in my previous comment.

Dillon

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Rcpp-devel <rcpp-devel-boun...@lists.r-forge.r-project.org> on behalf of 
Dillon Hammill <dillon.hamm...@anu.edu.au>
Sent: Wednesday, August 18, 2021 5:19:22 AM
To: Dirk Eddelbuettel <e...@debian.org>
Cc: rcpp-devel@lists.r-forge.r-project.org 
<rcpp-devel@lists.r-forge.r-project.org>
Subject: Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel

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 <e...@debian.org>
Sent: Tuesday, August 17, 2021 10:46:46 PM
To: Dillon Hammill <dillon.hamm...@anu.edu.au>
Cc: rcpp-devel@lists.r-forge.r-project.org 
<rcpp-devel@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 | e...@debian.org
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to