Reduction function called in a parfor loop cannot have more than two variables?
이전 댓글 표시
I'm sort of confused about the transparency policy in parfor loop. For example, this works:
a=zeros(10,1);
parfor i = 1:10
d=2;
x=(1:10)'+i;
a=mymax(a,x);
end
where mymax is a function:
function y=mymax(a,x)
b=[a;x];
[~,idx]=sort(b,'descend');
y=b(idx(1:10));
But this doesn't work (even if I replace mymax(a,x,d) with mymax(a,x,2)):
a=zeros(10,1);
parfor i = 1:10
d=2;
x=(1:10)'+i;
a=mymax(a,x,d);
end
where mymax is a function:
function y=mymax(a,x,d)
b=[a;x];
[~,idx]=sort(b,'descend');
y=b(idx(1:10))+d;
I've no idea why this doesn't work... It doesn't violate the transparency policy does it? How can I fix it? Is there any workaround for me to pass the constant d to the function mymax? Thanks a lot in advance!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!