<div dir="ltr"><div><div>Thanks Dirk! I think that does make sense. I'll work on trying to implement it. I don't think I'll get to it today, but I'll try to post back to the group if I arrive at a solution.<br><br></div>Thanks!<br></div>Brian<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 27, 2018 at 6:58 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 27 February 2018 at 18:38, brian knaus wrote:<br>
| Thanks for the suggestion! Unfortunately, I don't follow you. This is<br>
| likely because this is my first attempt at parallel code outside of one-off<br>
| mclapply(). My hope is to use this in a package on CRAN, so I'd like<br>
| something more portable than mclapply().<br>
|<br>
| My understanding is that we need to work with 'thread safe' data<br>
| structures. For example, in the worker in (<br>
| <a href="http://gallery.rcpp.org/articles/parallel-matrix-transform/" rel="noreferrer" target="_blank">http://gallery.rcpp.org/<wbr>articles/parallel-matrix-<wbr>transform/</a>)<br>
| RMatrix<double> is used for input and output matrices. And part of the<br>
| point of RMatrix and RVector are to provide these 'thread safe' data<br>
| structures so the rest of us do not need to learn the details of their<br>
| complexities. When you say I could try using std::vector<std::string> do<br>
| you mean as a substitute for RMatrix in the worker? Or perhaps<br>
| std::vector<std::vector<std::<wbr>string>> as a substitute for RMatrix?<br>
<br>
</span>RMatrix (and RVector) exist because we cannot use Rcpp::NumericMatrix (and<br>
Rcpp::NumericVector) as those are "proxy objects" which reuse the R-allocated<br>
memory. That is not thread safe as R may have a gc event.<br>
<br>
So converting your R text objects into std::vector<std::string> is also<br>
thread-safe as it provides a distinct copy. Which is why I suggested it<br>
earlier.<br>
<br>
You said you had string data, so you likely need something just like<br>
std::list<std::string> or std::vector<std::string> anyway.<br>
<br>
Does that make sense?   One word of caution, though:  RcppParallel and<br>
friends are user-friendly compared to doing it by hand using OpenMP etc, but<br>
not quite as easy as mlapply.  Maybe just cooking up a simpler C++ based<br>
package and have that used on the parallel instances governed by mclapply?<br>
<div class="HOEnZb"><div class="h5"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</div></div></blockquote></div><br></div>