#mclapply function comes from parallel R package library(parallel) # Check how many cores are requested by the job ( ncores <- as.numeric( Sys.getenv("NSLOTS") ) ) # If code is executed interactively, set the number of cores manually if ( is.na(ncores) ) ncores <- 1 # Define a function to be executed by each worker myFun <- function(x){ sum(x ) } # Define a sample dataset set.seed(42) df <- as.data.frame( matrix(sample(1:100, 100000000, replace=TRUE), nrow=100000) ) # Execute function in parallel using ncores CPU cores result <- mclapply( df, FUN=myFun, mc.cores = ncores )