2

以下のコードがどのように構成されているかについての入力をお願いします。より速く実行するために別の方法で編成する必要があるかどうかを知りたいです。具体的には、ネストされたループでforeachdoparを別々に使用する必要があるかどうかです。現在、内側のループが作業の大部分 (それぞれ 10 から 200 のレベルを持つ 1 から 8 のブレークダウン変数を持つ ddply) であり、それを並行して実行しています。簡単にするために、コードの詳細は省略しました。

何か案は?以下に整理されている私のコードは機能しますが、6 コア、41 GB のマシンでは数時間かかります。データセットはそれほど大きくありません (< 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 has about 50 rows

      # this uses the columns specified by k in the glm; the prior columns will be used as breakdown variables
      # up to 10 covariates
      result[[length(result) + 1]] <- foreach(k = 11:17, .packages=c('plyr','reshape2', 'fastmatch')) %dopar% {   

        ddply( 
          df,
          b,   # vector of breakdown variables
          function(x) { 

           # run a GLM and manipulate the output

          ,.parallel = TRUE) # close ddply
      } # close k loop -- set of covariates
    } # close i loop -- subsetting table
  } #close l -- group combinations
} # close m loop - this is the pairwise predictor matrix 

stopCluster(cl)
result <- unlist(result, recursive = FALSE)
tmp2<-do.call(rbind.fill, result)
4

1 に答える 1