小编ots*_*saw的帖子

并行处理和临时文件

我正在使用包中的mclapply函数multicore来进行并行处理.似乎所有子进程都开始为tempfile函数给出的临时文件生成相同的名称.即如果我有四个处理器,

library(multicore)
mclapply(1:4, function(x) tempfile())
Run Code Online (Sandbox Code Playgroud)

将给出四个完全相同的文件名.显然,我需要临时文件不同,以便子进程不会覆盖彼此的文件.当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 …
Run Code Online (Sandbox Code Playgroud)

random parallel-processing multicore r

5
推荐指数
2
解决办法
1528
查看次数

标签 统计

multicore ×1

parallel-processing ×1

r ×1

random ×1