[R] Parallel Programming

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Sep 21 07:00:49 CEST 2012


Then don't do that.

Use your script file to define functions. Source that file before the loop to load them into memory. Call those functions from within your loop.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Tjun Kiat Teo <teotjunk at gmail.com> wrote:

>I am trying to do parallel programming and I tried this
>
>library(doSNOW)
>library(foreach)
>
>testfunc<-function(x){
>x<-x+1
>x
>}
>
>noc<-2
>
>cl <- makeCluster(do.call(rbind,rep(list("localhost"),noc)), type =
>"SOCK")
>registerDoSNOW(cl)
>clusterExport(cl=cl,c("testfunc.r"))
>
>
>testl<-foreach(pp=1:2) %dopar% {
>testfunc(pp)
>}
>
>
>And this works but if I try to enclose my commands inside a text file
>to be sourced it doesn't work
>
>noc<-2
>
>testfunc<-function(x){
>x<-x+1
>x
>}
>
>cl <- makeCluster(do.call(rbind,rep(list("localhost"),noc)), type =
>"SOCK")
>
>registerDoSNOW(cl)
>
>clusterExport(cl=cl,c("a","testfunc.r"))
>
>testl<-foreach(pp=1:2)) %dopar% {
>source("test.r")
>}
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list