Michael
2012-Feb-22 22:19 UTC
[R] Writting to global variable in using doSNOW on multiple cores?
Hi all, Is there a problem when accessing/writing to global variable in using doSNOW package on multiple cores? In the below program, each of the MyCalculations(ii) writes to the ii-th column of the matrix "globalVariable"... Do you think the result will be correct? Will there be hidden catches? Thanks a lot! p.s. I have to write out to the global variable because this is a simplied example, in fact I have lots of outputs that need to be transported from within the parallel loops... therefore, probably the only way is to write out to global variables... library(doSNOW) MaxSearchSpace=44*5 globalVariable=matrix(0, 10000, MaxSearchSpace) cl<-makeCluster(7) registerDoSNOW(cl) foreach (ii = 2:nMaxSearchSpace, .combine=cbind, .verbose=F) %dopar% { MyCalculations(ii) } stopCluster(cl) [[alternative HTML version deleted]]