<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div>Apologies, I meant vector of vectors to RMatrix in my previous comment.</div>
<div><br>
</div>
<div dir="auto">Dillon</div>
<div><br>
</div>
<div id="ms-outlook-mobile-signature">Get <a href="https://aka.ms/AAb9ysg">Outlook for Android</a></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Rcpp-devel <rcpp-devel-bounces@lists.r-forge.r-project.org> on behalf of Dillon Hammill <Dillon.Hammill@anu.edu.au><br>
<b>Sent:</b> Wednesday, August 18, 2021 5:19:22 AM<br>
<b>To:</b> Dirk Eddelbuettel <edd@debian.org><br>
<b>Cc:</b> rcpp-devel@lists.r-forge.r-project.org <rcpp-devel@lists.r-forge.r-project.org><br>
<b>Subject:</b> Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel</font>
<div> </div>
</div>
<div>
<div>Thanks Dirk.</div>
<div><br>
</div>
<div dir="auto">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? </div>
<div dir="auto"><br>
</div>
<div dir="auto">What is the easiest way to perform this conversion (say for vector to RVector or vector of vectors to matrix)?</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks for your help.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Dillon</div>
<div dir="auto"><br>
</div>
<div><br>
</div>
<div id="x_ms-outlook-mobile-signature">Get <a href="https://aka.ms/AAb9ysg">Outlook for Android</a></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Dirk Eddelbuettel <edd@debian.org><br>
<b>Sent:</b> Tuesday, August 17, 2021 10:46:46 PM<br>
<b>To:</b> Dillon Hammill <Dillon.Hammill@anu.edu.au><br>
<b>Cc:</b> rcpp-devel@lists.r-forge.r-project.org <rcpp-devel@lists.r-forge.r-project.org><br>
<b>Subject:</b> Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel</font>
<div> </div>
</div>
<div class="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText"><br>
Dillon,<br>
<br>
The point of RMatrix and RVector in RcppParallel is to shield objects inside<br>
the RcppParallel blocks using Intel TBB from any interaction with the outer R<br>
process which may, or may not, run a gc() to rearrange its memory.<br>
<br>
Where they work, you should not use Rcpp's own NumericMatrix and alike. As for<br>
<br>
   Is there a way to write generic functions that will work in both cases?<br>
<br>
Yes, with care. Standard C++ should work. You have to 'arrange' functionality<br>
in such a way that you have "clean" internal functions (using STL objects<br>
and/or RMatrix and RVector) plus a wrapper making them callable from R).<br>
<br>
    Is it safe to create new objects on each thread<br>
<br>
Yes, but they have to standard C++ objects. At the once, your sums or<br>
reductions or ... have completed, converted to something you can return to R.<br>
<br>
The golden rule simply is 'no R objects in the inner core'.<br>
<br>
Hope this helps and was clear enough, I am still on my first coffee.<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="https://dirk.eddelbuettel.com">https://dirk.eddelbuettel.com</a> | @eddelbuettel | edd@debian.org<br>
</div>
</span></font></div>
</div>
</body>
</html>