0
我寫了下面的代碼(在RStudio的Windows上運行)讀取的非常大的文本文件很長的名單何時退出到內存循環:%dopar%並行foreach循環無法使用並行的foreach從函數中調用(R)
open.raw.txt <- function() {
files <- choose.files(caption="Select .txt files for import")
cores <- detectCores() - 2
registerDoParallel(cores)
data <- foreach(file.temp = files[1:length(files)], .combine = cbind) %dopar%
as.numeric(read.table(file.temp)[, 4])
stopImplicitCluster()
return(data)
}
然而不幸的是,該功能未能完成和調試表明,卡在foreach循環階段。奇怪的是,Windows任務管理器顯示,我在接近滿負荷處理器聰明(我有32個內核,這應該使用他們的30),10秒左右,然後回落到基線。然而循環從未完成,表明它正在完成工作,然後卡住。
更奇怪的是,如果我刪除「功能」一下,只是運行的每一步一個接一個,如下所示:
files <- choose.files(caption="Select .txt files for import")
cores <- detectCores() - 2
registerDoParallel(cores)
data <- foreach(file.temp = files[1:length(files)], .combine = cbind) %dopar%
as.numeric(read.table(file.temp)[, 4])
stopImplicitCluster()
然後一切工作正常。到底是怎麼回事?
更新:我運行該功能,然後離開它一段時間(大約一個小時),最後它完成。我不太清楚如何解釋這一點,因爲多核心仍然只在前10秒左右使用。這個問題可能與這些任務如何分享有關嗎?或者內存管理?我是新來的並行,所以不知道如何調查。
文件你是如何調用該函數? –
數據< - open.raw.txt() –
你能刪除調用從功能'stopImplicitCluster',看看是否這就是它的掛? –