Closed Zhuk66 closed 5 years ago
Can you simplify your example a bit?
For instance, the inner foreach
should never change as far as I understand.
Internal cycle can be executed using registerDoParallel or registerDoSEQ, it does not change the result. However the result is different if we use registerDoParallel (registerDoSEQ) or register_dopar_cmq (before external foreach).
Here is hack that solved this issue for me: In master.r I added a function: flatten <- function(data, rettype) { res <- list() for(i in 1:length(data)) { for(j in 1:length(data[[i]])) { res <- c(res, data[[i]][j]) } } type <- paste0('as.', rettype) res <- do.call(type, list(res)) return(res) }
... and I am calling it right after we've finished building a job_result: 83 } else # or else shut it down 84 qsys$send_shutdown_worker() 85 } 86 87 job_result <- flatten(job_result, rettype) 88 89 if (qsys$reusable || qsys$cleanup()) 90 on.exit(NULL) 91 92 summarize_result(job_result, n_errors, n_warnings, cond_msgs, 93 min(submit_index)-1, fail_on_error) 94 }
Minimal example:
register_dopar_cmq(n_jobs=0)
res = foreach(i=1:3, .combine=c) %dopar% sqrt(i)
cmp = foreach(i=1:3, .combine=c) %do% sqrt(i)
Fixed in 1f045e2.
I am trying to implement nested loops using clustermq and doParallel. I noticed incosistent behavior. For example: