我使用mclapply
功能在multicore
包做並行處理。似乎所有子進程都開始爲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.
如果丹尼爾提供了答案,他不應該得到綠色的標記嗎?其他人認爲什麼? – 2012-01-10 13:41:52
一個協調的方法是將此答案作爲對原始Q的編輯,並將解答的檢查提供給Daniel我的兩分錢。 – 2012-01-10 14:21:20