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.
Thanks! Brian On Tue, Feb 27, 2018 at 6:58 PM, Dirk Eddelbuettel <e...@debian.org> wrote: > > 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 ( > | http://gallery.rcpp.org/articles/parallel-matrix-transform/) > | 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 > earlier. > > 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? > > Dirk > > -- > http://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