[Rcpp-devel] Beginner Question: Two misc. questions on usage of Rcpp
Sunny Srivastava
research.baba at gmail.com
Tue Feb 1 02:27:56 CET 2011
Thank you Christian!
Yes, I am doing exactly that. From previous e-mail archives, I have
discovered that this is the advice that everyone gives.
As, I am on GNU/Linux, it seems (not sure) that it would be somewhat easier
than it is on Windows.
Best Regards,
S.
On Mon, Jan 31, 2011 at 7:22 PM, Christian Gunning <xian at unm.edu> wrote:
> > 2. I have a MCMC simulation (say: foo) which uses several functions (say:
> > fun1, fun2). These functions (fun1, fun2) are themselves computation
> > intensive and I used Rcpp to speed them. Until now I do something like
> this:
> >
> > In R file:
> >
> > foo <- function (...){
> >
> > src1 <- paste(readLines("fun1-rcpp.cpp"), collapse="\n")
> > RcppFun1 <- cxxfunction( .., plugin="Rcpp",body=src1)
> >
> > ## similar cpp code for fun2
> >
> > for (i in 1:10000){
> > ## use RcppFun1, RcppFun2 here
> > }
> > }
>
> For MCMC, independence of loop iterations argues for explicit
> parallelism. Assuming you have several cores available, look at the
> foreach package. If you have several *machines*, each with many cores
> available, something like the snowfall package might make sense,
> depending on communication costs.
>
> http://cran.r-project.org/web/packages/multicore/index.html
> http://cran.r-project.org/web/packages/foreach/index.html
>
>
> It's "yet another new thing", but as Dirk said, creating a package
> should help a lot for "real work". See ?Rcpp.package.skeleton to get
> started, and the "Writing R Extensions" manual for details. Exactly
> how to do this depends on OS (I don't know about windows shell), but
> the overview is:
>
> ## 1. Start R in directory to contain myPackage and run the following
> > Rcpp.package.skeleton("myPackage")
>
> ## 2. edit code in myPackage/R and myPackage/src directories
>
> ## 3. Run following commands from your OS shell,
> ## in the directory from step 1 (just above the package directory)
> R CMD check myPackage ## Optional
> R CMD INSTALL myPackage
>
> ## 4. Start R from any directory and do
> > require(myPackage)
>
> ## 5. After editing code, you must exit R and repeat steps 3 and 4
> ## to reload your package.
>
> best,
> Christian
> --
> A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110131/4646a67a/attachment.htm>
More information about the Rcpp-devel
mailing list