R/clusterMapLB.R

Defines functions clusterMapLB

clusterMapLB = function(cl, fun, ..., MoreArgs = NULL) {

  force(fun)
  args = list(...)
  force(MoreArgs)

  if (length(args) == 0L) {
    stop("need at least one argument")
  }
  n = viapply(args, length)
  vlen = max(n)
  ind = which(n != vlen)
  args[ind] = lapply(args[ind], rep, length = vlen)

  wrapper = function(i) do.call(fun, args = c(lapply(args, function(x) x[[i]]), MoreArgs))
  clusterApplyLB(cl, seq_len(vlen), wrapper)
}

Try the parallelMap package in your browser

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

parallelMap documentation built on June 28, 2021, 9:07 a.m.