[Rcpp-devel] Conversion of Rcpp::Vector Rcpp::List and Rcpp::Matrix to std objects - OpenMP
szehnder at uni-bonn.de
Fri May 31 21:51:01 CEST 2013
in addition to what Dirk said I can tell you, that at least Armadillo Objects do work accurate with OpenMP. I used in my code an '#pragma omp parallel for' directive on a lot of Armadillo matrices without any problems. Be aware of what clauses you use in your parallel setting.
There won't be a problem in parallel work, if you just read from matrices, but writing actions should be considered carefully. In case you need matrices in each thread which are manipulated individually make sure that you copy them for each thread (use the clause 'private(matrixName)' in the directive for the parallel region). Even if you have one matrix that collects al values from the threads, accessing in each thread different indices does work perfectly.
On May 31, 2013, at 7:37 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
> On 31 May 2013 at 18:00, Asis Hallab wrote:
> | Dear Rcpp Experts,
> | in my current project I wanted to make use of OpenMP.
> That works.
> | Unfortunately it seems Rcpp Objects cannot be used inside a block
> | executed in parallel.
> I think if you're careful it may work. You definitely do not want to call
> back or invoke R from multiple threads. But using Rcpp::NumericVector et al
> as "containers" may work.
> | Seg fault errors are the consequence, according to Dirk's reply in this thread
> | http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-February/003398.html
> | Hence the need to convert
> | Rcpp::Vector to std::vector,
> | Rcpp::Matrix to std::vector< std::vector >, and
> | Rcpp::List to std::map< std::string, … >
> | If I am not mistaken there's only support for the first conversion,
> | using the "as<> wrapper";
> | is this correct?
> | What would be the most efficient way of converting
> | Rcpp::Matrix and Rcpp::List to the above types?
> | And how to efficiently convert them back into Rcpp-Objects?
> See above. Not clear that you "must" convert. And you could use Armadillo
> types as well. That gives you matrix types.
> As for Rcpp::List conversions it depends on what the actual list elements
> are. You can always write yourself custom converter functions to get started.
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
More information about the Rcpp-devel