Parallelize 'BiocParallel' functions
Henrik Bengtsson
Source:vignettes/futurize-61-BiocParallel.md
futurize-61-BiocParallel.Rmd+
=

The futurize package allows you to easily turn
sequential code into parallel code by piping the sequential code to the
futurize() function. Easy!
TL;DR
You can use futurize to make BiocParallel functions to parallelize via any of the [parallel backends] supported by Futureverse, e.g.
Introduction
This vignette demonstrates how to use this approach to parallelize
functions such as bplapply(), bpmapply(), and
bpvec() in the BiocParallel package. For
example, consider the bplapply() function. It works like
base-R lapply(), but uses the BiocParallel
framework to process the tasks concurrently. It is commonly used
something like:
library(BiocParallel)
xs <- 1:1000
ys <- bplapply(xs, slow_fcn)The parallel backend is controlled by the
BiocParallel::register(), similar to how we use
future::plan() in futureverse. We can use the
futurize package to tell BiocParallel
to hand over the orchestration of parallel tasks to futureverse. All we
need to do is to pass the expression to futurize() as
in:
This will distribute the calculations across the available parallel workers, given that we have set parallel workers, e.g.
plan(multisession)The built-in multisession backend parallelizes on your
local computer and it works on all operating systems. There are other parallel
backends to choose from, including alternatives to parallelize
locally as well as distributed across remote machines, e.g.
plan(future.mirai::mirai_multisession)and
plan(future.batchtools::batchtools_slurm)Supported Functions
The futurize() function supports parallelization of all
BiocParallel functions that take argument
BPPARAM. Specifically,
-
bplapply()and.bplapply_impl() -
bpmapply()and.bpmapply_impl() bpvec()bpaggregate()
The following functions are currently not supported:
-
bpiterate()- technically supported, but because this function does not support usingDoparParam()with it, it effectively does not work withfuturize() bpvectorize()register()