3

I want to re-write some existing code I have using foreach and %dopar%. I am getting the error below when I run the complete code. The error only shows when i call the function (in line 9) - I am puzzled by the "cannot open connection". Any help is appreciated. The goal is to be able to run the function_test in parallel with different values taken from the vector z. Current code runs a a normal for loop and it is serialized.

z <- c("a","b","c","d","e","f","g","h")

    1    X <- 1:8
    2    system.time(
    3      foreach(x = X) %dopar% {
    4      arg1 <- 12 
    5      arg2 <- 90
    6      tmp1 <- df[df$a == z[x],] %>% dplyr::select(-starts_with("ABC"))
    7      tmp2 <- head(tmp1)
    8      tmp2
    9      tmp3 <- function_test (tmp1, arg1, arg2, "DEF", z[x])
    10    }
    11    )

    Error in { : task 1 failed - "cannot open the connection"
    In addition: Warning message:
    In mclapply(argsList, FUN, mc.preschedule = preschedule, mc.set.seed = set.seed,  :
      scheduled cores 8 encountered errors in user code, all values of the jobs will be affected
    Timing stopped at: 0.155 0.587 0.207
J.S
  • 117
  • 1
  • 8

0 Answers0