library("snow") library("parallel") cpu <- Sys.getenv("SLURM_CPUS_ON_NODE", 1) # Number of cores requested (use 1 core if running outside a job). hosts <- rep("localhost",cpu) cl <- makeCluster(hosts, type = "SOCK") # Create random matrices. n <- 5000 A <- matrix(rnorm(n^2),n) B <- matrix(rnorm(n^2),n) # Single core time of matrix multiplication of matrices # A and B. message("Single core matrix multiplication time: ") system.time(A %*% B) # Multiple core time of matrix multiplication of # matrices A and B. message("Parallel matrix multiplication time: ") system.time(parMM(cl, A, B)) # Stop cores properly. stopCluster(cl)