Skip to content
Prev 1715 / 2152 Next

Parallel multi-core processing for complex R functions

On Jul 14, 2013, at 11:13 PM, Alistair Perry wrote:

            
That's not true, you can use the matrix directly from the parallel code, because everything is shared. If you wrote your code using apply instead of a loop, you would have seen that all you need to do is to replace lapply with mclapply: You have

 rphi <- matrix(data = 0, nrow = nrow(ophi), ncol = NR)
 for (i in 1:NR) {    
    rnet <- rcc(net, option = reshuffle)
    rphi[, i] <- phi(rnet)
}

which can be simplified to

rphi <- sapply(seq.int(NR), function(i) phi(rcc(net, option=reshuffle)))

and thus the parallel version is simply

rphi <- simplify2array(mclapply(seq.int(NR), function(i) phi(rcc(net, option=reshuffle))))

Cheers,
Simon