Thank you Christian!<div><br></div><div>Yes, I am doing exactly that. From previous e-mail archives, I have discovered that this is the advice that everyone gives.</div><div><br></div><div>As, I am on GNU/Linux, it seems (not sure) that it would be somewhat easier than it is on Windows.</div>
<div><br></div><div>Best Regards,</div><div>S.<br><br><div class="gmail_quote">On Mon, Jan 31, 2011 at 7:22 PM, Christian Gunning <span dir="ltr"><<a href="mailto:xian@unm.edu">xian@unm.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">> 2. I have a MCMC simulation (say: foo) which uses several functions (say:<br>
> fun1, fun2). These functions (fun1, fun2) are themselves computation<br>
> intensive and I used Rcpp to speed them. Until now I do something like this:<br>
><br>
> In R file:<br>
><br>
> foo <- function (...){<br>
><br>
> src1 <- paste(readLines("fun1-rcpp.cpp"), collapse="\n")<br>
> RcppFun1 <- cxxfunction( .., plugin="Rcpp",body=src1)<br>
><br>
</div><div class="im">> ## similar cpp code for fun2<br>
><br>
> for (i in 1:10000){<br>
> ## use RcppFun1, RcppFun2 here<br>
> }<br>
> }<br>
<br>
</div>For MCMC, independence of loop iterations argues for explicit<br>
parallelism. Assuming you have several cores available, look at the<br>
foreach package. If you have several *machines*, each with many cores<br>
available, something like the snowfall package might make sense,<br>
depending on communication costs.<br>
<br>
<a href="http://cran.r-project.org/web/packages/multicore/index.html" target="_blank">http://cran.r-project.org/web/packages/multicore/index.html</a><br>
<a href="http://cran.r-project.org/web/packages/foreach/index.html" target="_blank">http://cran.r-project.org/web/packages/foreach/index.html</a><br>
<br>
<br>
It's "yet another new thing", but as Dirk said, creating a package<br>
should help a lot for "real work". See ?Rcpp.package.skeleton to get<br>
started, and the "Writing R Extensions" manual for details. Exactly<br>
how to do this depends on OS (I don't know about windows shell), but<br>
the overview is:<br>
<br>
## 1. Start R in directory to contain myPackage and run the following<br>
> Rcpp.package.skeleton("myPackage")<br>
<br>
## 2. edit code in myPackage/R and myPackage/src directories<br>
<br>
## 3. Run following commands from your OS shell,<br>
## in the directory from step 1 (just above the package directory)<br>
R CMD check myPackage ## Optional<br>
R CMD INSTALL myPackage<br>
<br>
## 4. Start R from any directory and do<br>
> require(myPackage)<br>
<br>
## 5. After editing code, you must exit R and repeat steps 3 and 4<br>
## to reload your package.<br>
<br>
best,<br>
Christian<br>
<font color="#888888">--<br>
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<br>
</font></blockquote></div><br></div>