I have a 4 core Mac with 8 threads. My understanding of mclapply()
is that it should utilize the 8 threads as processors, but when I run my script I only see 4 threads working. In my example, I am using a nested list because in my real work I have a 6 tier nested list that will take several days to run. I will be running my script on a 24 core Linux, so I am trying to understand how I can best utilize my resources.
library(zoo)
x = replicate(150000, rnorm(24))
list1 <- list(elem1 <- x, elem2 <- x)
nested_list <- list(elem1 = list1, elem2 = list1)
mclapply(nested_list, FUN = function(x){
lapply(x, FUN = function(y){
rollmean(y, 7)
})
})
When I monitor my CPUs while running this script, I see this;
The even numbered cores do not seem to be working at all, and Core 1 seems to be to capable of doing more.
Is mclapply()
not as simple as a drop-in replacement for lapply()
? The actual functions that I am using come from specific packages that I need to use, so I cannot change functions to be more efficient (ie using dplyr
functions instead of base
functions). Please advise how I can use resources more efficiently.