[Rcpp-devel] RcppParallel with string or char?
edd at debian.org
Wed Feb 28 03:58:33 CET 2018
On 27 February 2018 at 18:38, brian knaus wrote:
| Thanks for the suggestion! Unfortunately, I don't follow you. This is
| likely because this is my first attempt at parallel code outside of one-off
| mclapply(). My hope is to use this in a package on CRAN, so I'd like
| something more portable than mclapply().
| My understanding is that we need to work with 'thread safe' data
| structures. For example, in the worker in (
| RMatrix<double> is used for input and output matrices. And part of the
| point of RMatrix and RVector are to provide these 'thread safe' data
| structures so the rest of us do not need to learn the details of their
| complexities. When you say I could try using std::vector<std::string> do
| you mean as a substitute for RMatrix in the worker? Or perhaps
| std::vector<std::vector<std::string>> as a substitute for RMatrix?
RMatrix (and RVector) exist because we cannot use Rcpp::NumericMatrix (and
Rcpp::NumericVector) as those are "proxy objects" which reuse the R-allocated
memory. That is not thread safe as R may have a gc event.
So converting your R text objects into std::vector<std::string> is also
thread-safe as it provides a distinct copy. Which is why I suggested it
You said you had string data, so you likely need something just like
std::list<std::string> or std::vector<std::string> anyway.
Does that make sense? One word of caution, though: RcppParallel and
friends are user-friendly compared to doing it by hand using OpenMP etc, but
not quite as easy as mlapply. Maybe just cooking up a simpler C++ based
package and have that used on the parallel instances governed by mclapply?
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel