【发布时间】:2011-07-12 20:25:01
【问题描述】:
我正在使用multicore 包中的mclapply 函数进行并行处理。似乎所有启动的子进程都会为tempfile 函数给出的临时文件生成相同的名称。即,如果我有四个处理器,
library(multicore)
mclapply(1:4, function(x) tempfile())
将给出四个完全相同的文件名。显然我需要临时文件不同,以便子进程不会覆盖彼此的文件。当间接使用tempfile 时,即调用一些调用tempfile 的函数时,我无法控制文件名。
有没有办法解决这个问题? R 的其他并行处理包(例如foreach)是否有同样的问题?
更新:自 R 2.14.1 起,这不再是问题。
CHANGES IN R VERSION 2.14.0 patched:
[...]
o tempfile() on a Unix-alike now takes the process ID into account.
This is needed with multicore (and as part of parallel) because
the parent and all the children share a session temporary
directory, and they can share the C random number stream used to
produce the uniaue part. Further, two children can call
tempfile() simultaneously.
【问题讨论】:
标签: r random parallel-processing multicore