Population growth rates with mclapply()
As a Statistical Programmer, you do a lot of bootstrapping in R. One of the routine analyses you conduct is to bootstrap a distribution for the mean population growth rate for different countries across a given time period.
The current code in production uses a PSOCK cluster and parLapply()
to parallelize this process for efficient execution. However, this is still running slow for production needs. Your boss has asked you to compare the performance of PSOCK vs. FORK clusters.
gr_list
has been loaded in your workspace. Each element of gr_list
contains population growth rates for a given country from 2001 to 2021. The bootstrap function, boot_dist()
, is also available. parallel
and microbenchmark
packages have been loaded.
Este exercício faz parte do curso
Parallel Programming in R
Instruções do exercício
- Use the FORK version of
parLapply()
. - Supply the list of inputs.
- Supply the function to apply to each element of input.
- Specify four cores for the FORK cluster.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
microbenchmark(
"PSOCK" = {
cl <- makeCluster(4)
parLapply(cl, gr_list, boot_dist)
stopCluster(cl)
},
# Use the FORK version of parLapply()
"FORK" = ___(
# Supply input
___,
# Supply function to apply
___,
# Specify number of cores
___ = ___),
times = 1)