Skip to content
Prev 2777 / 10988 Next

[Rcpp-devel] New self-contained OpenMP example (Was: Stack imbalance warning when using Rcpp and OpenMP)

On August 25, 2011 05:32:45 PM Dirk Eddelbuettel wrote:
[...]
[...]
I know you wanted to keep all code looking the same, but with std::transform 
all serial code is very short:

serialStdAlgCode <- '
   std::vector<double> x = Rcpp::as<std::vector< double > >(xs);
   std::transform(x.begin(), x.end(), x.begin(), ::log);
   return Rcpp::wrap(x);
'
funSerialStdAlg <- cxxfunction(signature(xs="numeric"), body=serialStdAlgCode, 
plugin="Rcpp")

serialStdAlgRcppCode <- '
   Rcpp::NumericVector x = Rcpp::NumericVector(xs);
   std::transform(x.begin(), x.end(), x.begin(), ::log);
   return x;
'
funSerialStdAlgRcpp <- cxxfunction(signature(xs="numeric"), 
body=serialStdAlgRcppCode, plugin="Rcpp")

The results (without OpenMP because I'm currently on a single-core CPU):

                    test replications elapsed relative user.self sys.self
3 funSerialStdAlgRcpp(z)           20   4.236 1.000000     3.792    0.252
4       funSerialRcpp(z)           20   4.312 1.017941     3.792    0.272
5        funSugarRcpp(z)           20   4.537 1.071058     3.744    0.588
2     funSerialStdAlg(z)           20   5.514 1.301700     4.329    0.884
1           funSerial(z)           20   5.536 1.306893     4.480    0.808

Davor