@@ -3,6 +3,7 @@ title: Faster Multivariate Normal densities with RcppArmadillo and OpenMP
3
3
author : Nino Hardt, Dicko Ahmadou, Benjamin Christoffersen
4
4
license : GPL (>= 2)
5
5
tags : armadillo openmp featured
6
+ updated : Feb 2, 2020
6
7
summary : Fast implementation of Multivariate Normal density using RcppArmadillo and OpenMP.
7
8
layout : post
8
9
src : 2013-07-13-dmvnorm_arma.Rmd
@@ -179,6 +180,10 @@ variables for us:
179
180
// [[ Rcpp::plugins(openmp)]]
180
181
{% endhighlight %}
181
182
183
+ When used in a package, the standard ` src/Makevars ` supplied by the package
184
+ ensures the variable ` $(SHLIB_OPENMP_CXXFLAGS) ` is used. It relies on the R
185
+ configuration to automatically add OpenMP support where available.
186
+
182
187
We also need to set the number of cores to be used before running the
183
188
compiled functions. One way is to use ` detectCores() ` from the ` parallel `
184
189
package.
@@ -335,13 +340,13 @@ benchmark(
335
340
336
341
<pre class =" output " >
337
342
test replications elapsed relative
338
- 4 dmvnrm_arma_mc 100 0.931 1.000
339
- 6 dmvnrm_arma_fast 100 3.617 3.885
340
- 3 dmvnrm_arma 100 5.572 5.985
341
- 5 dmvnrm_arma_old 100 7.739 8.313
342
- 2 dmvnorm_arma 100 9.219 9.902
343
- 7 dMvn 100 12.453 13.376
344
- 1 dmvnorm 100 14.326 15.388
343
+ 4 dmvnrm_arma_mc 100 0.875 1.000
344
+ 6 dmvnrm_arma_fast 100 3.622 4.139
345
+ 3 dmvnrm_arma 100 5.274 6.027
346
+ 5 dmvnrm_arma_old 100 7.433 8.495
347
+ 2 dmvnorm_arma 100 8.649 9.885
348
+ 7 dMvn 100 12.563 14.358
349
+ 1 dmvnorm 100 14.637 16.728
345
350
</pre >
346
351
347
352
Lastly, we show that the functions yield the same results:
0 commit comments