Parallelism is useful if it improves the speed of a slow program. If speed
doesn't improve then parallelism is an unnecessary complication.
autoparallel
transforms programs from serial into multicore parallel, and
then benchmarks the modified program to determine if the transformation
increases the speed.
The word 'program' means a collection of valid R statements. Typically this means a script or a function.
We begin with the simplest and most obvious way to transform a program.
Top level occurences of lapply, mapply, Map
are changed to mclapply,
mcmapply, mcMap
from the parallel
package, and the run times are
compared. Below lapply, mapply, Map
are referred to as the 'target
statements'.
This technique may be useful if the following conditions are met:
Consider the following simple program:
# simple.R ffast = function(x) rnorm(1) fslow = function(x){ Sys.sleep(0.1) rnorm(1) } z = 1:10 r1 = lapply(z, ffast) r2 = lapply(z, fslow)
To make this run faster the last line should be changed to:
r2 = parallel::mclapply(x, fslow)
To transform it:
library(autoparallel) benchmark_transform("simple.R", output = "simple2.R")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.