I think that if you do @sync @parallel for nn in doset ... end
Then it will wait to finish before continuing execution. On Wednesday, July 9, 2014 7:22:06 PM UTC+3, Thomas Covert wrote: > > alright that didn't do it either. when I run this code interactively the > "write to disk" steps get executed before the @parallel for is done > running, even if the contents of the for is just a function call. > > is there a way to not execute the stuff after the @parallel for until that > code itself is done running? > > thanks. > > -thom > > On Wednesday, July 9, 2014 10:43:32 AM UTC-5, Thomas Covert wrote: >> >> I don't quite have a solution to my own question, but does this have to >> do with the multi-line nature of the above @parallel for? i.e., if I were >> to wrap up the if statement into a single function call, would things work >> properly? >> >> On Wednesday, July 9, 2014 8:40:26 AM UTC-5, Thomas Covert wrote: >>> >>> I'm having trouble debugging some @parallel for code, pasted below. In >>> particular, Julia seems to execute the "saving to disk" code before all of >>> the parallel workers have finished. Why is this? >>> >>> If the details are needed, "dsm" and "fnm" are bool arrays, >>> (theta0,y,X,Ds,M,G,T,Xs) are data not modified during this code block, and >>> gvals/vvals are SharedArray's to store results. "doset" is an array of >>> integers. "gprD" is a non-mutating function that I have @everywhere'd >>> previously >>> >>> any ideas? Thanks in advance. >>> >>> -thom >>> >>> @parallel for nn in doset >>> >>> if sum(fnmasks[:,nn]) >= 1 >>> >>> println("doing obs $nn") >>> >>> fnm = fnmasks[:,nn] >>> >>> dsm = dsmasks[:,nn] >>> >>> g,v = gprD(theta0,y[dsm,1],X[dsm,:],Ds[fnm,fnm,:],M[fnm,:], >>> >>> G[fnm,dsm],T[fnm,1],Xs[:,:,1],tDsPnn[fnm,:,:]) >>> >>> >>> gvals[:,nn] = g >>> >>> vvals[:,nn] = v >>> >>> end >>> >>> end >>> >>> >>> println("saving to disk") >>> >>> gvals2 = convert(Array,gvals) >>> >>> vvals2 = convert(Array,vvals) >>> >>> save("results/gv.jld","gvals",gvals2,"vvals",vvals2) >>> >>