Extended functionality and usability for distributed code that is based on the snowfall package.
install.packages(c("twMisc","twSnowfall"), repos="http://R-Forge.R-project.org")
library(twSnowfall) ?twSnowfall
#sfInit(parallel=TRUE,cpus=2) X <- matrix(0:9,nrow=5,ncol=2) dimnames(X) <- list( rows=paste("r",1:nrow(X),sep=""), cols=paste("c",1:ncol(X),sep="") ) Y <- X*10 # delivering row i of X and row i of Y as arguments to F_Apply F_ARGS <- function(i){list(arg1=X[i,],arg2=Y[i,])} F_APPLY <- paste .res <- sfFArgsApplyLB( nrow(X), F_ARGS, F_APPLY, sep="-")
#sfInit(parallel=TRUE,cpus=2) # using as many cpus as rows in Z (Z<-matrix(letters[1:12],nrow=3)) F_APPLY <- function(x,z) paste(x,z,sep=""); F_ARGS <- function(i,prevRes){list(x=prevRes,z=Z[i])} .res0 <- rep("_",nrow(Z)) # dependStep will be length of .res0 resSeq <- sfFArgsApplyDep( length(Z), F_ARGS, F_APPLY, .res0) (res <- matrix(sfSimplifyLBResult(resSeq),nrow=nrow(Z)))This gives the same results as having one parallel call per column. However, in this implementation, the finished nodes do not need to wait for possibly slower finishing of other rows, and can tackle already further columns.
#sfInit(parallel=TRUE,cpus=2) sfExport("sfRemoteWrapper",namespace="twSnowfall") suppressWarnings(dir.create("tmp")) # will store to tmp subdirectory .remoteDumpfileBasename=file.path("tmp","testDump2") .remoteDumpfile <- paste(.remoteDumpfileBasename,".rda",sep="") unlink(.remoteDumpfile) # throwing an error on remote process fTestStop <- function(){ stop("test throwing an error") } tmp <- try( sfClusterCall( sfRemoteWrapper, remoteFun=fTestStop, remoteDumpfileBasename=.remoteDumpfileBasename ) ) # inspecting what was wrong in interactive R-session load(.remoteDumpfile) #debugger(get(.remoteDumpfileBasename))
The project summary page you can find here.