Why is my parfor loop not running?

조회 수: 36 (최근 30일)
Marc Laub
Marc Laub 2020년 6월 10일
댓글: Edric Ellis 2020년 6월 11일
Hello,
I guess this question has been asked multiple times. I did all the troubleshooting before but I still dont undersatdn why my following parfor loop wont run.
seeds=NaN(volume/4*num_pts,3,volume/4);
parfor i=1:volume/4
pts=partial_seeder(min_grain,num_pts);
ptRads = seeder(pts);
seeds(:,1:2,i)=pts;
seeds(:,3,i)=ptRads;
end
function pts=partial_seeder(min_grain,num_pts)
pts=NaN(num_pts,2);
pts(1,:)=rand(1,2)*2*10^-3;
id=2;
while id<=num_pts
pts_new=rand(1,2)*2*10^-3;
d=pdist2(pts_new,pts(1:id-1,:));
if min(d)>=min_grain
pts(id,:)=pts_new;
id=id+1;
else
continue
end
end
end
I preallocated my array seeds and I dont know why Matlab would be unable to classify my variable seeds. It should just calculate the functions partial_seeder and seeder in parallel and write the results into seeds... not sure why it wont work.
Many Thanks in advance
best regards
  댓글 수: 1
Edric Ellis
Edric Ellis 2020년 6월 11일
As it happens, I already provided the answer to this question before I'd even seen the question - see here https://www.mathworks.com/matlabcentral/answers/545921-how-to-use-fetchnext-correctly . Basically, this is a parfor slicing constraint - you're not allowed two different assignment expressions into seeds - you have to make a temporary variable for each iteration of the parfor loop so that you can make only a single assignment.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by