我想就我的以下代码的结构提供输入。想知道是否需要以不同的方式组织它以更快地执行。具体来说,我是否需要在嵌套循环中以不同的方式使用foreach和dopar。目前,内部循环是大部分工作(ddply 有 1-8 个细分变量,每个变量有 10-200 个级别),这就是我并行运行的内容。为简单起见,我省略了代码细节。
有任何想法吗?我的代码(如下组织的)确实有效,但在 6 核 41gb 机器上需要几个小时。数据集不是那么大(< 20k 记录)。
for(m in 1:length(Predictors)){ # has up to three elements in the vector
# construct the dataframe based on the specified predictor
# subset the original dataframe based on the breakdown variables, outcome, predictor and covariates
for(l in 1:nrow(pairwisematrixReduced)){ # this has 1-6 rows;subset based on correct comparison groups
# some code here
cl <- makeCluster(detectCores())
registerDoParallel(cl)
for (i in 1:nrow(subsetting_table)){ # this table …Run Code Online (Sandbox Code Playgroud)