Is it possible, in R parallel::mcparallel, to limit the number of cores used at any one time? -


in r, mcparallel() function in parallel package forks off new task worker each time called. if machine has n (physical) cores, , fork off 2n tasks, example, each core starts off running 2 tasks, not desirable. rather able start running n tasks on n workers, , then, each tasks finishes, submit next task now-available core. there easy way this?

my tasks take different amounts of time, not option fork off tasks serial in batches of n. there might workarounds, such checking number of active cores , submitting new tasks when become free, know of simple solution?

i have tried setting cl <- makeforkcluster(nnodes=n), indeed set n cores going, these not used mcparallel(). indeed, there appears no way feed cl mcparallel(). latter has option mc.affinity, it's unclear how use , doesn't seem want anyway (and according documentation functionality machine dependent).

i'd suggest taking advantage of higher level functions in parallel include functionality instead of trying force low level functions want.

in case, try writing tasks different arguments of single function. can use mclapply() mc.preschedule parameter set true , mc.cores parameter set number of threads want use @ time. each time task finishes , thread closes, new thread created, operating on next available task.

even if each task uses different bit of code, can create list of functions , pass wrapper function. example, following code executes 2 functions @ time.

f1 <- function(x) {x^2} f2 <- function(x) {2*x} f3 <- function(x) {3*x} f4 <- function(x) {x*3} params <- list(f1,f2,f3,f4) wrapper <- function(f,inx){f(inx)} output <- mclapply(params,fun=calling,mc.preschedule=true,mc.cores=2,inx=5) 

if need make params list of lists including various parameters passed each function function definition. i've used approach various tasks of different lengths , works well.

of course, may various tasks different calls same function, in case can use mclapply directly without having write wrapper function.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -