armstrtw / CppBugs

c++ version of BUGS
29 stars 5 forks source link

multicore utilization #12

Open 20csummer opened 11 years ago

20csummer commented 11 years ago

Hi all,

I'm new to CppBugs. First I want to say this project is truly awesome and thanks for the excellent work.

As a statistician and C++ amateur, I'm wondering does CppBugs support multithread/core utilization? If yes, how do I code and compile with such option?

My current compiling option is -mavx -g -O3 -std=c++0x -larmadillo

and it seems cppbugs is only using one core, so my program runs pretty slow. I tried adding in -lboost_thread-mt, but it doesn't help.

Thanks in advance for any help!

armstrtw commented 11 years ago

Thanks for the support.

The way to use multicore is to use a multithreaded lapack/blas. you will then benefit from the speed up directly in the matrix ops.

It's very hard to multi-thread the sampler itself. I think you'll find some research in that area if you search online. One other possibility is to do a simple parallel loop to sum of the logp's of each node. Since, most models only have a few nodes (single digits typically), I'm not sure how much benefit one would get out of this change.

Feel free to email me the model if you want some help trying to speed it up.

-Whit

20csummer commented 11 years ago

Hi Whit,

Thanks for the fast reply. For some reason, the R wrapped version of cppbugs can utilize four cores so it runs much faster than pure C++. I'll investigate the differences.

Thanks again

armstrtw commented 11 years ago

Yeah, there's a whole art to getting this configured correctly. Which version of lapack/blas you pick up will depend on how your armadillo was set up when it was installed.

Dirk has done a lot of work on the R packages to make sure they point to R's lapcack and blas.

you might try re-installing http://packages.debian.org/source/sid/openblas and then doing a reconfig on lapack.

There is also 'GOTO_NUM_THREADS' assuming you are using goto blas.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/174211

-Whit

20csummer commented 11 years ago

I realized the problem of my code is that I used loops instead of vectors/matrices in the major part of deterministic functions. After vectoring everything, now it runs blazingly fast!

Thanks again!

armstrtw commented 11 years ago

Great.

That's good to hear. Good luck!

-Whit

On Thu, Mar 28, 2013 at 12:04 PM, 20csummer notifications@github.comwrote:

I realized the problem of my code is that I used loops instead of vectors/matrices in the major part of deterministic functions. After vectoring everything, now it runs blazingly fast!

Thanks again!

— Reply to this email directly or view it on GitHubhttps://github.com/armstrtw/CppBugs/issues/12#issuecomment-15596989 .