library(raster)
## Loading required package: sp
library(parallel)
setwd('~/Downloads/03')
cores <- 3
pliki <- dir(pattern = "tif")[1:100]
indeksy <- splitIndices(nx = length(pliki), ncl = cores)
policz_sume <- function(x){
sum(stack(pliki[x]))
}
# system.time(mclapply(indeksy, FUN = policz_sume, mc.cores = cores ))
# system.time(sum(stack(pliki)))
r <- mclapply(indeksy, FUN = policz_sume, mc.cores = cores )
r <- Reduce('+',r)
plot(r)