Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


kinor
Posts:
181
Registered:
11/19/09


Re: performance of parfor
Posted:
Apr 5, 2013 10:49 AM


Edric M Ellis <eellis@mathworks.com> wrote in message <ytw6201w39j.fsf@ukeellis0l.dhcp.mathworks.com>... > "kinor " <kinor.removethiswithdot@gmx.de> writes: > > > I used parfor a while ago and it worked quite well (2.5 time faster > > with 3 labs). Now I tried to use it on win 7 with 2012a and an > > example from > > http://blogs.mathworks.com/loren/2007/10/03/parforthecourse/ with > > the following results: > > > > matlabpool local 3 > > > > n = 600; > > tic > > ranks = zeros(1,n); > > parfor (ind = 1:n) > > ranks(ind) = rank(magic(ind)); % last index could be ind,not nind+1 > > end > > toc > > > > tic > > ranks = zeros(1,n); > > for (ind = 1:n) > > ranks(ind) = rank(magic(ind)); % last index could be ind,not nind+1 > > end > > toc > > > > Starting matlabpool using the 'local' profile ... connected to 3 labs. > > Elapsed time is 10.773548 seconds. > > Elapsed time is 13.993966 seconds. > > > > Which is surprisingly slow for 3 labs. I would be really grateful for > > any hint to get the 3 labs working. > > The MATLAB function 'RANK' is instrinsically multithreaded. On a single > machine, it's always going to be more efficient to use intrinsic > multithreading than to use explicit parallelism using a MATLABPOOL and > PARFOR because of the overheads of distributing the body of the loop to > the workers. MATLABPOOL workers run in "single computational thread" > mode, so to make a fair comparison, you should start MATLAB using > "singleCompThread". > > Cheers, > > Edric.
Hi Edric,
thanks a lot for this clear explanation. I should have read the example more carefully, now there is a certain gain in speed by parfor: double speed with 3 labs.
I looked in the help of rank, its multithreading is not mentioned there, where did you know that?
As a simple example I tried to generate an image with the following function:
function speedtest maxNumCompThreads(1); matlabpool(3) n = 6000; k = ones(n, n, 3); fh = {@r @g @b};
tic for c = 1:3 k(:,:,c) = fh{c}(ones(n)); end toc
tic parfor c = 1:3 k(:,:,c) = fh{c}(ones(n)); end toc
matlabpool close
function rV = r(k) for y = size(k,1):1:1 for x = size(k,2):1:1 rV(y,x) = sin(y*0.1)*cos(x*0.2); end end
function rV = g(k) for y = size(k,1):1:1 for x = size(k,2):1:1 rV(y,x) = sin(y*0.015)*cos(x*0.12); end end
function rV = b(k) for y = size(k,1):1:1 for x = size(k,2):1:1 rV(y,x) = sin(y*0.1)*cos(x*0.2); end end
in 2012a i got: Starting matlabpool using the 'local' profile ... connected to 3 labs. Elapsed time is 8.331768 seconds. Elapsed time is 11.959129 seconds. Sending a stop signal to all the labs ... stopped.
which means a loss of speed applying parfor to long executing functions. I am curious if there is any explanation for this.
Cheers kinor



