Path: news.mathworks.com!not-for-mail
From: Edric M Ellis <eellis@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problem with parfor
Date: Fri, 23 Oct 2009 10:28:16 +0100
Organization: The Mathworks, Ltd.
Lines: 31
Message-ID: <ytw1vkuihn3.fsf@uk-eellis-deb5-64.mathworks.co.uk>
References: <hbrljb$7os$1@fred.mathworks.com>
NNTP-Posting-Host: uk-eellis-deb5-64.mathworks.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: fred.mathworks.com 1256290097 15735 172.16.27.232 (23 Oct 2009 09:28:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 23 Oct 2009 09:28:17 +0000 (UTC)
X-Face: $Ahg}Iylezql"r1WV1Me5&)ng"a4v%D>==KMs-elCfj"o}$bh-VOt7lVXgLWsC?9mZ`mINT
 G6PDvca;nrgs$lfcr0l1ew'N]>nXKl}m|Zpg>,6*gLp~-N0N2*+b.iwv=u>@R$L4SEG&NYUU;lSR@u
 IHphdAy
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)
Cancel-Lock: sha1:9h3lnmlIf6lNfOvY+uCxW8HSIhY=
Xref: news.mathworks.com comp.soft-sys.matlab:579530


"Pravin " <pravinkakar@gmail.com> writes:

> I am currently trying to improve the performance of a program I am working on
> by carrying out operations in parallel. The basic code that I am using for
> this operation is something like:
>
> for i = 1:Mdivs
>     parfor j = 1:Ndivs
>                 pic = fun1(img1((i-1)*step+1:min([factor+(i-1)*step,M]),(j-1)*step+1:min(factor+(j-1)*step,N),:));
>         motion(i,j,:) = fun2(pic);
>     end
> end

Unfortunately, the subscripted assignment error appears to be due to a bug in
PARFOR which incorrectly deals with some assignments - in this case, because
you're slicing the second dimension out of 3. One workaround for this problem is
to move the PARFOR loop to be the outer loop (generally a good idea in any
case), but to do this you'll also need to calculate a whole chunk of your
"motion" array, something like this:

parfor i = 1:Mdivs
  tmp = zeros( Ndivs, 2 );
  for j = 1:Ndivs
    tmp( j, : ) = fun2( fun1( ... ) );
  end
  motion( i, :, : ) = tmp;
end

Cheers,

Edric.