r - 如何在降雪时输出消息?

标签 r snowfall

我正在 Windows 7 上使用降雪包进行模拟研究。

我喜欢每 10 次运行向主 R 控制台打印一条消息以监控进度,但它没有这样做。 IE。什么都没有打印

任何帮助都感激不尽。

runsim = function(nsim,n,mean,var){
cov = 0
for(i in 1:nsim){
if ( i %% 10==0) 
cat("\n Running simulation",i)
dat = function1(n,mean,var)

cov = ...
}
cov / nsim
}
sfExport("function1","runsim")
sfLibrary(library1)

wrapper = function(n){
runsim(100,n,0.5,0.25)
}

Out<-sfLapply(1:100,wrapper)

最佳答案

查看 ?sfCat并找到它说的那一行:

sfCat is a debugging function printing a message on all slaves (which appear in the logfiles).



这告诉我们需要在对 sfInit 的调用中启用日志记录。 (参数 slaveOutfile )。然后,每次调用 sfCat()会将内容转储到您指定的日志文件中。我也花了一段时间才弄清楚;-)

代码示例
if (!require("snowfall")) {
    install.packages("snowfall")
    require("snowfall")
}

sfInit(parallel=TRUE, cpus=4, slaveOutfile="test.txt")
sfLibrary("snowfall", character.only=TRUE)

res <- sfClusterApplyLB(1:100, function(x) {
    sfCat(paste("Iteration ", x), sep="\n")
})
sfStop()
./test.txt 的输出
[...]

Calling a snowfall function without calling 'sfInit' first or after sfStop().
'sfInit()' is called now.
snowfall 1.84 initialized: sequential execution, one CPU.

Iteration  4
Type: EXEC 
Iteration  92
Type: EXEC 
Iteration  94
Type: EXEC 
Iteration  96
Type: EXEC 
Iteration  98
Type: EXEC 
Iteration  100
ype: EXEC 
Iteration  29
Type: EXEC 
Iteration  31
Type: EXEC 
Iteration  33
Type: EXEC 
Iteration  35
Type: EXEC 
Iteration  37
Type: EXEC 
Iteration  39
Type: EXEC 
Iteration  41
Type: EXEC 
Iteration  43
Type: EXEC 
Iteration  45
Type: EXEC 
Iteration  47
Type: EXEC 
Iteration  49
Type: EXEC 
Iteration  51
Type: EXEC 
Iteration  53
Type: EXEC 
Iteration  55
Type: EXEC 
Iteration  57
Type: EXEC 
Iteration  59
Type: EXEC 
Iteration  61
Type: EXEC 
Iteration  63
Type: EXEC 
Iteration  65
Type: EXEC 
Iteration  67
Type: EXEC 
Iteration  69
Type: EXEC 
Iteration  71
Type: EXEC 
Iteration  73
Type: EXEC 
Iteration  75
Type: EXEC 
Iteration  77
Type: EXEC 
Iteration  79
Type: EXEC 
Iteration  81
Type: EXEC 
Iteration  83
Type: EXEC 
Iteration  85
Type: EXEC 
Iteration  87
Type: EXEC 
Iteration  89
Type: EXEC 
Iteration  91
Type: EXEC 
Iteration  93
Type: EXEC 
Iteration  95
Type: EXEC 
Iteration  97
Type: EXEC 
Iteration  99
 EXEC 
Iteration  74
Type: EXEC 
Iteration  76
Type: EXEC 
Iteration  78
Type: EXEC 
Iteration  80
Type: EXEC 
Iteration  82
Type: EXEC 
Iteration  84
Type: EXEC 
Iteration  86
Type: EXEC 
Iteration  88
Type: EXEC 
Iteration  90

自己的问题

有谁知道如何“控制”进入日志文件的具体内容?
例如,最好包含有关哪个 worker 完成了哪个工作等的信息。

关于r - 如何在降雪时输出消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8860470/

相关文章:

r - 如何根据 R 树形图中的类对分支进行着色?

html - 在一些背景图像上使用 css3 的降雪效果

html - CSS3 降雪动画禁用内部链接

r - 并行运行时写入全局环境

r - 并行进程的通信 : what are my options?

在 R 中并行运行函数

r - 合计 : sum not meaningful for factors

r - 创建一个包含一行和多列的数据框

R:选择包含给定数量 NA 的行

r - 无法在两个日期列上使用 dplyr 连接