0
我想用488個光柵文件計算GLCM。由於計算時間龐大,我想要使用我的多核處理器(AMD Phenom II 6核)的所有功能。R中三重for循環的最新多核計算
library("glcm")
library(raster)
library(devtools)
install_github('azvoleff/glcm')
setwd(working dir.)
rasters <- list.files()[grep("()\\w*.tif", list.files())]
statistics <- c("mean", "variance", "homogeneity", "contrast", "dissimilarity", "entropy","second_moment", "correlation")
shift1 <- c(0,0,1,1)
shift2 <- c(0,1,0,1)
for (j in 1:length(rasters)){
raster1 <- raster(rasters[j])
for (i in 1:length(statistics)){
for (k in 1:length(shift1)){
GLCM <- glcm(raster1, window=c(11,11), statistics=statistics[i], shift = c(shift1[k],shift2[k]), na_opt="ignore")
file <- paste("./GLCM/", substr(tiles[j],0,nchar(tiles[j])-4),"_", statistics[i], "_shift_",shift1[k], shift2[k] , ".tif", sep="")
writeRaster(GLCM, filename = file, type = "GTIFF")
}
}
gc()
}
我在網上搜索了R中的多核解決方案,但是找不到哪一個是最新的。所以我希望有人能幫助我。
你發現了哪些解決方案? 'doParallel'和'doMC'與'foreach'一起工作,在2個月前更新。 'multicore'也是一個不錯的選擇。你在使用什麼操作系統? –
從多個核心獲取價值的問題是要有一個並行算法。我不清楚你是否已經解決了這個問題。 –
@JakeBurkhead我發現了這些,但不知道如何將這些代碼應用於這些代碼。 @BondedDust:我如何知道'glcm'是否是一種並行算法? – loki