##PROBLEM: it hangs! during execution of FOREACH with %dopar%
##PS: hint: it hangs when nrow(m) > ncore!!!
##PROBLEM: with R version 4.5.2
##PROBLEM: with R version 4.6.0 (2026-04-24 ucrt)
library(doParallel)
library(foreach)
a1 = 10
a2 = 10
ncore = 5
##ncore = a1 * a2 - 5
cl <- makeCluster(ncore, type = "MIRAI")
registerDoParallel(cl)
m <- matrix(rnorm(a1 * a2), a1, a2)
func1 <- function(m) {
rr <- foreach(i = 1:nrow(m), .combine = rbind) %dopar% {
(m[i, ] / mean(m[i, ])) }
return (rr)
}
##tictoc::tic()
rr2 <- func1(m)
##tictoc::toc()
stopCluster(cl)
##PROBLEM: it hangs! during execution of FOREACH with %dopar%
##PS: hint: it hangs when nrow(m) > ncore!!!
##PROBLEM: with R version 4.5.2
##PROBLEM: with R version 4.6.0 (2026-04-24 ucrt)
library(doParallel)
library(foreach)
a1 = 10
a2 = 10
ncore = 5
##ncore = a1 * a2 - 5
cl <- makeCluster(ncore, type = "MIRAI")
registerDoParallel(cl)
m <- matrix(rnorm(a1 * a2), a1, a2)
func1 <- function(m) {
rr <- foreach(i = 1:nrow(m), .combine = rbind) %dopar% {
(m[i, ] / mean(m[i, ])) }
return (rr)
}
##tictoc::tic()
rr2 <- func1(m)
##tictoc::toc()
stopCluster(cl)