Parallel Programming and R
Parallel Programming and R
Bjrn-Helge Mevik
Research Infrastructure Services Group, USIT, UiO
Parallel programming in R
1 / 13
Introduction
Simple example
Practical use
The end. . .
Parallel programming in R
2 / 13
Introduction
Background
R is single-threaded
Parallel programming in R
3 / 13
Introduction
Overview of parallel
I
Introduced in 2.14.0
Parallel programming in R
4 / 13
Simple example
Serial version:
## The worker function to do the calculation:
workerFunc <- function(n) { return(n^2) }
## The values to apply the calculation to:
values <- 1:100
## Serial calculation:
res <- lapply(values, workerFunc)
print(unlist(res))
Bjrn-Helge Mevik (RIS)
Parallel programming in R
5 / 13
Simple example
Parallel programming in R
6 / 13
Simple example
I
I
I
I
MPI:
I
I
I
I
I
Parallel programming in R
7 / 13
Simple example
Parallel programming in R
8 / 13
Simple example
Parallel programming in R
9 / 13
Practical use
Parallel programming in R
10 / 13
Practical use
Extended example
(Notes to self:)
I
Submit jobs
Go through scripts
Look at results
Parallel programming in R
11 / 13
Practical use
Efficiency
The time spent in each invocation of the worker function should not
be too short
If the time spent in each invocation of the worker function vary very
much, try the load balancing versions of the functions
Avoid copying large things back and forth:
I
I
I
Parallel programming in R
12 / 13
The end. . .
Other topics
There are several things we havent touched in this lecture:
I
Resources:
I
Parallel programming in R
13 / 13