workers: Worker Management Functions

Description Usage Arguments Details See Also Examples

Description

The startWorkers function is used to start a specified number of workers to execute tasks in parallel. The stopWorkers function is used to shutdown the workers in the specified worker group object.

Usage

1
2
3
startWorkers(workerCount=getOption('cores'), FORCE=FALSE,
  tmpdir=tempdir(), verbose=FALSE)
stopWorkers(obj)

Arguments

workerCount

The number of worker processes to start on the local machine. The default is the value of getOptions('cores'). If that isn't set, then three workers are started.

FORCE

A logical value indicating whether another worker group should be stopped in order to allow this group to be started. This is useful if previous sessions were started, but not stopped properly.

tmpdir

The path of a directory in which to create temporary files.

verbose

A logical value indicating whether verbose messages should be displayed.

obj

The worker group object to stop.

Details

The startWorkers function returns a "worker group" object, which represents the workers to evaluate tasks. That object is passed to the registerDoSMP function for use by the foreach function. It is important to subsequently call the stopWorkers function, or the workers won't be stopped, but will keep running after your R session exits. System IPC resources will also be retained. This will cause subsequent calls to startWorkers to issue warning and error messages. IPC resources can be deleted using the rmSessions function.

See Also

registerDoSMP, rmSessions

Examples

1
2
3
4
5
# start two workers, compute some square roots, and shutdown
w <- startWorkers(2)
registerDoSMP(w)
foreach(i=1:3) %dopar% sqrt(i)
stopWorkers(w)

doSMP documentation built on May 2, 2019, 5:35 p.m.