1
我發現如果在並行計算過程中有多個打印功能,則只有最後一個打印功能會顯示在控制檯上。所以我設置了文件選項,並希望我能得到每個打印的結果。這裏是R代碼:如何在並行計算中寫出日誌?如何調試並行計算?
cl <- makeCluster(3, type = "SOCK",outfile="log.txt")
abc <<- 123
clusterExport(cl,"abc")
clusterApplyLB(cl, 1:6,
function(y){
print(paste("before:",abc));
abc<<-y;
print(paste("after:",abc));
}
)
stopCluster(cl)
但我只是得到三個記錄:
starting worker for localhost:11888
Type: EXEC
Type: EXEC
[1] "index: 3"
[1] "before: 123"
[1] "after: 2"
Type: EXEC
[1] "index: 6"
[1] "before: 2"
[1] "after: 6"
Type: DONE
投給'outfile =「」',它節省了我的一天 –