R/foreach_helper.R

Defines functions foreach_split

# splits a job of n replication into equally sized jobs for all foreach workers
# if more than min jobs are requested!
# returns a vector with the number of replications for each worker
foreach_split <- function(n, min = 100) {
  if (n <= min)
    return(n)
    
  nw <- foreach::getDoParWorkers()
  ns <- rep(ceiling(n / nw), times = nw)
  dif <- sum(ns) - n
  if (dif > 0)
    ns[1:dif] <- ns[1:dif] - 1
  
  ns
}

Try the pomdp package in your browser

Any scripts or data that you put into this service are public.

pomdp documentation built on Sept. 9, 2023, 1:07 a.m.