[Rcpp-devel] Input on code design implementing a MCMC algorithm in R and improving performance with RcppArmadillo

Dirk Eddelbuettel edd at debian.org
Fri Apr 10 20:20:02 CEST 2020


On 10 April 2020 at 13:05, Joonwook Park wrote:
| A while ago, I did exactly what you are trying to do. I converted my MCMC
| code in Matlab to R although it does not involve Kalman filter forward
| filtering and backward smoothing algorithm. I converted one program that
| takes the most of the time to RCpp with the help of others and used
| other modules as in R. My experience was not as positive as others may have
| had as it takes about 7 days to run 10,000 iterations with R for the same
| data, which normally takes about 7 hours in Matlab. It was a fun project

It all depends. I once inherited a Matlab project running many hours which I
was able to translate gaining a) a noticeable speed up from going from Matlab
(which isn't slow) to C++ (which is still faster) coupled with b) the fact
that it was embarassingly data parallel so we could also run multiple
instances in parallel.

I think the combination made it close to 100x but it has been a few years.

In short, it all depends.  And nothing in life is free -- the above cost some
time re-writing the code carefully.

| but it might be a better idea to build a new program from scratch in R and
| RCpp rather than converting an existing Matlab program to R.  I did use
| list variable type for data, parameters, and storage for MCMC run. If you
| are familiar with Matlab, the conversion to R and RCpp would not take much
| time and obviously you have a fantastic community that lends their hands
| should you have any questions (Thank you Dirk!). Obviously there is a code
| optimization issue, which I am not so familiar with R and RCpp, that led to
| increasing computing time in my case. My goal was to build new programs in
| R for the future but I was discouraged by the speed. You can also try
| Microsoft R which happens to utilize more CPU cores than plain R. Best

[ Sorry, but that was already false when they launched the product (as you then
could have used Goto BLAS or later Open BLAS) and is even more false now (as
Intel MKL _used to_ only be available with Microsoft R but it now available
for everybody; for Ubuntu/Debian I wrote a simple script here which remains
moderately popular:  https://github.com/eddelbuettel/mkl4deb -- in short
there is now even less differentiating Microsoft R from the standard R. ]

Dirk

| wishes for your attempt.

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list