0

我有这样的功能:

parLapply(cl, 1:400, function(exponent) 2^exponent)

R 现在会将任务拆分为每个核心的均匀部分。

我怎样才能将其更改为,让我们说:

100 - 核心_0 50 - 核心_1 ...

?

4

1 回答 1

0

您可以将向量从 1 到 400 包装到一个列表中,如下所示:

library(parallel)

cl <- makeCluster(getOption("cl.cores", 2))

library(microbenchmark)

microbenchmark(
  even = {
    res1 <- unlist(parLapply(cl, 1:4000, function(x) {
      2^x
    }))
  },
  odd = {
    res2 <- unlist(parLapply(cl, list(1:3000, 3001:4000), function(x) {
      2^x
    }))
  },
  times = 5
)
于 2018-01-22T14:01:47.277 回答