makeParallel: Make Parallel Code From Serial

Description Usage Arguments Details Value Examples

View source: R/makeParallel.R

Description

makeParallel is a high level function that performs all the steps to generate parallel code.

Usage

1
2
3
4
5
6
7
makeParallel(code, isFile = file.exists(code), expr = if (isFile)
  parse(code, keep.source = TRUE) else parse(text = code, keep.source =
  FALSE), data = NULL, nWorkers = parallel::detectCores(),
  platform = Platform(nWorkers = nWorkers), run = FALSE,
  scheduler = schedule, ..., generator = generate,
  generatorArgs = list(), outFile = FALSE, prefix = "gen_",
  overWrite = FALSE)

Arguments

code

file name or a string containing code to be parsed

isFile

logical, is the code a file name?

expr

expression, for example from parse

data

list of data descriptions. Each element is a DataSource. The names of the list elements correspond to the variables in the code that these objects are bound to.

nWorkers

integer, number of parallel workers

platform

Platform describing resource to compute on

run

logical, evaluate the code once to gather timings?

scheduler,

function to produce a Schedule from a TaskGraph.

...

additional arguments to schedule methods

generator

function to produce GeneratedCode from a Schedule

generatorArgs

list of named arguments to use with generator

outFile

character name of the file to write the generated script. If FALSE then don't write anything to disk. If TRUE and code comes from a file then use prefix to make a new name and write a script.

prefix

character added to front of file name

overWrite

logical write over existing generated file

Details

The following are the high level steps:

  1. Infer the task graph

  2. Schedule the statements

  3. Generate parallel code

The arguments allow the user to control every aspect of this process. For more details see vignette("makeParallel-concepts").

Value

code object of class GeneratedCode

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Make an existing R script parallel
script <- system.file("examples/mp_example.R", package = "makeParallel")
makeParallel(script)

# Write generated code to a new file
newfile <- tempfile()
makeParallel(script, file = newfile)

# Clean up
unlink(newfile)

# Pass in code directly
d <- makeParallel(expr = parse(text = "lapply(mtcars, mean)"))

# Examine generated code
writeCode(d)

# Specify a different scheduler
pcode <- makeParallel("x <- 1:100
y <- rep(1, 100)
z <- x + y", scheduler = scheduleTaskList)

# Some schedules have plotting methods
plot(schedule(pcode))

clarkfitzg/codedoctor documentation built on Nov. 18, 2020, 4:34 p.m.