0
我正在讀取超過100個文件的目錄中的csv文件,然後我正在做一些東西,我有8個核心cpu,所以我想在並行模式下完成更快。如何在R中進行並行處理?
我寫了一些代碼,但它不爲我工作 - (使用Linux)
library(data.table)
library(parallel)
# Calculate the number of cores
no_cores <- detectCores() - 1
# Initiate cluster
cl <- makeCluster(no_cores)
processFile <- function(f) {
# reading file by data.table
df <- fread(f,colClasses = c(NA,NA, NA,"NULL", "NULL", "NULL"))
A <- parLapply(cl,sapply(windows, function(w) {return(numOverlaps(w,df))}))
stopCluster(cl)
}
files <- dir("/home/shared/", recursive=TRUE, full.names=TRUE, pattern=".*\\.txt$")
# Apply the function to all files.
result <- sapply(files, processFile)
正如你看到的我想在processFile(A),但它不能正常工作運行的功能!
如何在並行處理模式下運行該功能?
因爲我使用「data.table」包和讀表時以「FREAD」(內部parLapply功能)我有錯誤,我無法讀取文件時,它不適合我的工作! –
@BigData沒有(可重現的)代碼很難說。如果你提供了一段代碼(生成數據,寫入磁盤,用fread讀取...)我可以嘗試任何使它並行工作。 –
我更新了我正在讀fread函數的代碼,我的意思是我在函數中包含了這一行 - 我遇到的錯誤是:checkForRemoteErrors(val)中的錯誤: 7個節點產生錯誤;第一個錯誤:無法找到函數「fread」 - –