R中的多核和data.table

时间:2022-07-14 23:23:22

I am attempting to use multicore function parallel with data.table and am unable to quite come up with the right way to do this. Code:

我试图使用与data.table并行的多核函数,我无法想出正确的方法来做到这一点。码:

require(multicore)
require(data.table)
dtb = data.table(a=1:10, b=1:2)
x = dtb[,parallel(a+1),by=b]

> x
   b   pid fd
1: 1 12243  3
2: 1 12243  6
3: 2 12247  4
4: 2 12247  8

I would like to call collect() on this but these are no longer parallel objects. How should one do this?

我想在这上面调用collect(),但这些不再是并行对象。怎么应该这样做?

1 个解决方案

#1


3  

I think this is along the lines of what you want:

我认为这与你想要的一致:

collect(dtb[, list(jobs = list(parallel(a+1))), by = b][, jobs])

The reason you didn't have parallel objects any more and couldn't run a collect is because you were converting them to a list, instead of storing them in a list, which is what I did above.

之所以没有并行对象并且无法运行收集,是因为您将它们转换为列表,而不是将它们存储在列表中,这就是我上面所做的。

#1


3  

I think this is along the lines of what you want:

我认为这与你想要的一致:

collect(dtb[, list(jobs = list(parallel(a+1))), by = b][, jobs])

The reason you didn't have parallel objects any more and couldn't run a collect is because you were converting them to a list, instead of storing them in a list, which is what I did above.

之所以没有并行对象并且无法运行收集,是因为您将它们转换为列表,而不是将它们存储在列表中,这就是我上面所做的。