1
跟进一些data.table
并行(1)(2)(3)我试图弄明白。 这个语法有什么问题?平行data.table - 什么是正确的语法
library(data.table)
set.seed(1234)
dt <- data.table(id= factor(sample(1L:10000L, size= 1e6, replace= TRUE)),
val= rnorm(n= 1e6), key="id")
foo <- function(l) sum(l)
dt2 <- dt[, foo(.SD), by= "id"]
library(parallel)
cl <- makeCluster(detectCores())
dt3 <- clusterApply(cl, x= parallel:::splitRows(dt, detectCores()),
fun=lapply, FUN= function(x,foo) {
x[, foo(data.table:::".SD"), by= "id"]
}, foo= foo)
stopCluster(cl)
# note that library(parallel) is annoying and you often have to do this type ("::", ":::") of exporting to the parallel package
Error in checkForRemoteErrors(val) : 4 nodes produced errors; first error: incorrect number of dimensions
cl <- makeCluster(detectCores())
dt3 <- clusterApply(cl, x= parallel:::splitRows(dt, detectCores()),
fun=lapply, FUN= function(x,foo) {
x <- data.table::data.table(x)
x[, foo(data.table:::".SD"), by= "id"]
}, foo= foo)
stopCluster(cl)
Error in checkForRemoteErrors(val) : 4 nodes produced errors; first error: object 'id' not found
我的语法玩耍了不少。这两个似乎是我能得到的最接近的。显然有些东西还是不对的。
我真正的问题是类似的结构,但有更多的行,我正在使用24核心/ 48个逻辑处理器的机器。所以看我的电脑使用大约4%的计算能力(仅使用1个内核)真的很烦人
看起来很有趣 - 如何正确一个指定端口? –
@Alex您可以在'Rserve :: Rserve()'调用中指定端口,然后在与'rscl.connect'连接时使用相同的端口。你可以使用单个端口并且有多个单独处理的连接,但我更愿意在自己的端口上隔离每个R节点。 – jangorecki
我的问题与'库(Rserve)'没有特别清楚记录的事实有关。所以,假设我有24个内核。我是否将代码修改为'ports < - 6311:6324'?还有别的吗?我尝试过在'rscl.assign(...)'有一个大的停顿,看起来好像有很多以太网活动,但没有CPU/RAM活动。这是预期的吗? –