if (FALSE) {
# Init Snowfall with settings from sfCluster
##sfInit()
# Init Snowfall with explicit settings.
sfInit( parallel=TRUE, cpus=2 )
if( sfParallel() )
cat( "Running in parallel mode on", sfCpus(), "nodes.\n" )
else
cat( "Running in sequential mode.\n" )
# Define some global objects.
globalVar1 <- c( "a", "b", "c" )
globalVar2 <- c( "d", "e" )
globalVar3 <- c( 1:10 )
globalNoExport <- "dummy"
# Define stupid little function.
calculate <- function( x ) {
cat( x )
return( 2 ^ x )
}
# Export all global objects except globalNoExport
# List of exported objects is listed.
# Work both parallel and sequential.
sfExportAll( except=c( "globalNoExport" ) )
# List objects on each node.
sfClusterEvalQ( ls() )
# Calc something with parallel sfLappy
cat( unlist( sfLapply( globalVar3, calculate ) ) )
# Remove all variables from object.
sfRemoveAll( except=c( "calculate" ) )
}
Run the code above in your browser using DataLab