有关如何在R程序中创建循环计数器的一些信息性帖子.但是,在使用带有"foreach()"的并行化版本时,如何创建类似的功能?
我似乎无法使用mcforkfrom 在Rstudio中分叉一个新进程parallel,尽管这可以在linux/OS X上的标准R控制台中运行.是否有另一种解决方法来在Rstudio中分支子进程.
例如,考虑这个功能:
library(parallel)
f <- function() {
p <- parallel:::mcfork()
if (inherits(p, "masterProcess")) {
cat("I'm a child!")
parallel:::mcexit()
}
cat("I'm the master\n")
}
Run Code Online (Sandbox Code Playgroud)
在我的标准R控制台中,我得到了预期的输出:
I'm the master
> I'm a child!
Run Code Online (Sandbox Code Playgroud)
但在Rstudio中,我得到:
I'm the master
Run Code Online (Sandbox Code Playgroud) 我的问题与这个问题有关.但是,上面引用的问题使用的multicore是被替换的包parallel.无法在parallel包中复制响应中的大多数功能.有没有办法跟踪进度mclapply.在查看mclapply文档时,有一个名为的参数mc.silent,我不确定这是否能够跟踪进度,如果可以,我们如何以及在哪里可以看到日志文件?我在ubuntulinux OS 上运行.请参阅下面的重复性示例,我想对其进行处理.
require(parallel)
wait.then.square <- function(xx){
# Wait for one second
Sys.sleep(2);
# Square the argument
xx^2 }
output <- mclapply( 1:10, wait.then.square, mc.cores=4,mc.silent=FALSE)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.