Garrett Catlin

August 24, 2022

Tracking Progress During mclapply()

In the last couple of months, I've been utilizing parallel computing more often with mclapply() and mcmapply() in library(parallel). For those unfamiliar, here's a great introduction to what parallelization is and how to use it in R

As someone who likes to see progress while my code is running, for example printing the iteration in a loop, I was curious if there was an analog for parallelization as message(), print(), etc. don't work. Turns out you have to use your machine's echo function:

library(parallel)

numCores = detectCores()

test = function(it) {
  system(paste0("echo '",it,"'"))
  it
}

store = mclapply(1:10, test, mc.cores = numCores)

Here's what the console looks like:

> store = mclapply(1:10, test, mc.cores = numCores)
1
2
3
4
5
6
7
9
10
8
>

This is going here mostly so I'll remember where to look in the inevitable scenario that I forget 😅.

Trying to make the word "parallelization" sound natural out loud,

Garrett C.
catlin@hey.com

About Garrett Catlin

Your friendly neighborhood data scientist.