私はRに少し慣れていないので、ここで初心者の色合いを許してください...
各ファイルのデータに対して関数を実行し、結果の値をベクトルに格納するスクリプトで、保存された数千のデータフレーム (ファイル) をロードするコードを R で書いています。さまざまな機能でこれを何度も行う必要があり、現時点では非常に時間がかかっています。
マルチコア mclapply を使用してプロセスを並列化しようとしていますが、残念ながら、2 コアから 8 コアまでは、単に 1 コアで実行するよりもさらに時間がかかるようです。
ディスク I/O の制限により、この考えは根本的に不健全ですか? マルチコア、あるいは R でさえ、適切なソリューションではないのでしょうか? Python などでファイルを開き、内容に対して R 関数を実行するのは、R よりも優れたパスでしょうか?
これに関するガイダンスや考えをいただければ幸いです -
わかりやすくするために追加されたコード:
library(multicore)
project.path = "/pathtodata/"
#This function reads the file location and name, then loads it and runs a simple statistic
running_station_stats <- function(nsrdb_stations)
{
varname <- "column_name"
load(file = paste(project.path, "data/",data_set_list[1], sep = ""))
tempobj <- as.data.frame(coredata(get(data_set_list[2])))
mean(tempobj[[varname]],na.rm=TRUE)
}
options(cores = 2)
#This file has a list of R data files data_set_list[1] and the names they were created with data_set_list[2]
load(file = paste(project.path, "data/data_set_list.RData", sep = ""))
thelist <- list()
thelist[[1]] <- data_set_list[1:50,]
thelist[[2]] <- data_set_list[51:100,]
thelist[[3]] <- data_set_list[101:150,]
thelist[[4]] <- data_set_list[151:200,]
#All three of these are about the same speed to run regardless of the num of cores
system.time(
{
apply(nsrdb_stations[which(nsrdb_stations$org_stations==TRUE),][1:200,],1,running_station_stats)
})
system.time(
lapply(thelist, apply, 1, running_station_stats)
)
system.time(
mclapply(thelist, apply, 1, running_station_stats)
)