hanging %*% in a foreach %dopar% loop

191 views Asked by At

Trying to strike the right balance with the amount of detail to give here, because I can't create a mwe. My foreach loop hangs in the middle of some matrix calculations. Oddly enough, it hangs on my imac but not on my larger (ie more memory) linux machine. It hangs if I use %dopar% but is fine with %do%. It always hangs on the seventh iteration of the interior for loop. It always hangs on the 'colSums' step, but I calculate the colSums using matrix algebra rather than colSums. If I use colSums, I can get it to work. It's not that my matrix dimensions are incorrect - I've checked them and am not receiving an error. What could be going on?

helper <- function(mat){
    vec <- rep(0, dim(mat)[1])
    for(j in 1:7){
        mat <- mat^(j*0.1)
        vec <- vec + (rep(1, dim(mat)[1]) %*% mat)               # ----- hangs here
    }
    return(vec)
}

foreach(ind = 1:10, .packages = 'Matrix') %dopar% {
     helper(mat = mat)
}
0

There are 0 answers