Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中捕获新线程的输出_R_Multithreading_Parallel Processing_Output_Snow - Fatal编程技术网

在R中捕获新线程的输出

在R中捕获新线程的输出,r,multithreading,parallel-processing,output,snow,R,Multithreading,Parallel Processing,Output,Snow,我正在运行一个多线程的R脚本,但是在从集群生成输出时遇到了问题 outFun <- function() { cat(sample(0:9,1)); } require(snow) clust <- makeCluster(4) clusterExport(clust,"outFun") clustFun <- function(i){outFun()} clusterApplyLB(clust,1:8,clustFun) outFunmakeClusteroutfile

我正在运行一个多线程的R脚本,但是在从集群生成输出时遇到了问题

outFun <- function()
{
  cat(sample(0:9,1));
}
require(snow)
clust <- makeCluster(4)
clusterExport(clust,"outFun")
clustFun <- function(i){outFun()}
clusterApplyLB(clust,1:8,clustFun)

outFunmakeCluster
outfile=”“
选项不适用于Windows上的Rgui,因为Rgui不会将子进程的输出发送到显示窗口。但是,
outfile=”“
确实与Rterm程序配合使用,因为它是一个简单的控制台程序:

C:\Program Files\R\R-3.0.2\bin\i386> rterm -q
> library(parallel)
> clust <- makeCluster(4, outfile="")
starting worker pid=1596 on localhost:11862 at 09:13:30.005
starting worker pid=1192 on localhost:11862 at 09:13:30.342
starting worker pid=1616 on localhost:11862 at 09:13:30.679

R不是多线程的。@dwn正如我在上面的代码中所演示的,有一些包可以使它成为多线程的……有趣的解决方案,不会想到问题出在IDE中。
> clusterEvalQ(clust, message("hello"))
hello
hello
hello
hello
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL