The sleigh allows R functions to be
executed in parallel using the eachElem
and
eachWorker
methods.
The sleigh workers are started when the sleigh object is
constructed. When tasks are submitted to the sleigh, using the
eachWorker
and eachElem
methods, the workers execute the tasks
and return the results. When the stopSleigh
method is called, the
workers are stopped.
A given R program can create multiple sleigh objects, each of which will have its own set of workers. This can be useful if tasks have different requirements. For example, you could create a Linux sleigh and a Windows sleigh, and submit Windows-specific tasks only to your Windows sleigh.
sleigh(...)
or
new("sleigh",...)
where ...
can be one or more of the following named arguments:
nodeList
:launch='local'
. The default value
is c('localhost', 'localhost', 'localhost')
.workerCount
:launch='local'
. The default value is 3.launch
:'local'
(the default) or 'web'
, or to a function object. The function is called once for each worker listed in nodeList
. It
is passed two arguments: a name from nodeList
, and an
environment object that was constructed by merging defaultSleighOptions
with the arguments that were passed to the sleigh constructor. The
function should return a character vector, where the first element is the
command to execute, and the subsequent elements are the command arguments.
For example, the function could return the vector
c('ssh', '-f', 'host')
, where 'host'
is the first
argument to the launch function. This
isn't the complete command to be executed; it's the 'remote execution'
portion of the command.
The sleigh constructor will add the rest of the command based on the
scriptExec
argument. Note that the command is expected to return after
launching the worker. That is why the ssh -f option is used in the example. nwsHost
:nwsPort
:scriptExec
:scriptcmd
function on Windows, and uses envcmd
function on
other platforms.scriptDir
:scriptName
:RNWSSleighWorker.py
on Windows, and RNWSSleighWorker.sh
on other platforms.workingDir
:logDir
:NULL
.outfile
:NULL
.wsNameTemplate
:'sleigh_ride_%010d'
.user
:NULL
.verbose
:FALSE
.signature(.Object = "sleigh")
:
sleigh class constructor.signature(.Object = "sleigh")
:
evaluate the given function with multiple argument sets using
the workers in sleigh.signature(.Object = "sleigh")
:
evaluate the given function exactly once for each worker in sleigh.signature(.Object = "sleigh")
:
get sleigh's rankCount.signature(.Object = "sleigh")
:
return the status of the sleigh.signature(.Object = "sleigh")
:
shut down workers and remove sleigh workspace.signature(.Object = "sleigh")
:
get number of workers started in sleigh.'local'
, sshcmd
,
rshcmd
, lsfcmd
, sshforwardcmd
, and 'web'
) to
tailor the client's working environment. This is done
by setting launch variable to a function (sshcmd
, rshcmd
,
sshforwardcmd
or lsfcmd
)
or a string ('local' and 'web'). See the examples section.## Not run:
# # Default option: create three sleigh workers on local host:
# s <- sleigh()
# # which is equivalent to:
# s <- sleigh(launch='local')
#
# # Create sleigh workers on multiple machines using SSH:
# s <- sleigh(nodeList=c('n1', 'n2', 'n3'), launch=sshcmd)
#
# # Use the LSF bsub command to launch ten workers:
# s <- sleigh(nodeList=rep('fake', 10), launch=lsfcmd)
#
# # Use web launch:
# s <- sleigh(launch='web')
# ## End(Not run)
Run the code above in your browser using DataLab