Works for me. What versions of julia & Images are you running? But wow is it slow. A comprehension in a single process is considerably faster, presumably because of the use of vcat. I think you'll be far happier if you either run single-threaded or preallocate a SharedArray for the output.
Your code is also in an awkward middle ground: it tries to exploit julia's ability to have fast loops, but other inefficiencies (like computing inv(Sigma) freshly for each pixel rather than just once) will kill you. Probably your best bet is to do a single reinterpret at the beginning to convert the whole thing to an array, and use matrix algebra in vectorized form for the entire image. Alternatively, rewrite the pixelwise code to avoid so much allocation. Best, --Tim On Wednesday, March 25, 2015 11:31:50 AM Archibald Pontier wrote: > Hi everyone, > > I recently started using Julia for my projects and I'm currently quite > stuck by how to parallelize things. > > I've got the two following functions: > > @everywhere pixel(p) = [p.r, p.g, p.b]; > > which takes a RGB pixel (as defined in the Images module) and converts it > into a vector of its RGB components (in my case always Float64), and > > @everywhere function p_theta(pixel, mu, Sigma) > Sigma = inv(Sigma); > d = size(mu, 1); > temp = dot(-(pixel - mu), Sigma * (pixel - mu)) / 2; > result = (sqrt(det(Sigma)) * exp(temp) / sqrt((2*pi)^2)) > return result; > end > > which calculates the probability for a given pixel, given a 3 components > vector mu and a 3x3 covariance matrix Sigma. > > Now, when I use them without parallelizing, there is no problem. However, > as soon as I use them in parallel, for example, given an image img > > s = size(img, 1) * size(img, 2); > t_img = reshape(img, s) > > s_D = @parallel (vcat) for i in 1:s > p = pixel(t_img[i]); > d = p_theta(p, mu, Sigma); > d > end > > it crashes with the following error: > ERROR: result shape not specified in _reinterpret_cvarray at > ~/.julia/v0.3/Images/src/core.jl:140 > all the child processes terminate, and I end up with only 1 julia process > left. > > I tried various things, including pmap, without success. > > Any idea why that happens? > > Thanks in advance!
