parfor problem (broadcast variable)

조회 수: 6 (최근 30일)
HYUNGJUN PARK
HYUNGJUN PARK 2020년 9월 18일
편집: Matt J 2020년 9월 18일
Hi, I'm trying to use "parfor" in my MATLAB script.
It goes well without error, but It shows no significant speed boost compared to for loop.
And I got this warning message:
"the entire array ('A_Data' , 'A_ref') is a broadcast variable. This might result in unnecessary communication overhead."
How can I deal with this problem?
Note that:
A_Data: 1710203x5 double
A_ref: 5760x5 double
Please suggest the solutions.
% load 'A_Data' and 'A_ref' matrix
load dataq.mat
% preallocation ('theta' ,'b_ref')
k=length(A_ref);
theta=zeros(k,5);
b_ref=zeros(k,1);
% regression
poolobj = parpool(8);
parfor i=1:k
W = sqrt( ...
exp( ...
-( ...
( ( A_Data(:,2)-A_ref(i,2) ) / 0.6 ).^2+ ...
( ( A_Data(:,3)-A_ref(i,3) ) / 0.6 ).^2+ ...
( ( A_Data(:,4)-A_ref(i,4) ) / 0.6 ).^2+ ...
( ( A_Data(:,5)-A_ref(i,5) ) / 0.6 ).^2 ...
) /2 ...
) ...
);
theta(i,:)=regress(W.*b_Data,repmat(W,1,5).*A_Data);
b_ref(i,1)=A_ref(i,:)*theta(i,:)';
end
delete(poolobj);

답변 (1개)

Matt J
Matt J 2020년 9월 18일
편집: Matt J 2020년 9월 18일
There's never any gaurantee parfor will be faster, but I would modify the code as follows,
B_Data=A_Data(:,2:5)/(0.6*2);
B_ref=A_ref(:,2:5)/(0.6*2);
parfor i=1:k
W = exp(sum( -( B_Data-B_ref(i,:) ) ).^2 ,2) ;
theta(i,:)=regress(W.*b_Data,W.*A_Data);
end
b_ref=A_ref*theta.';

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by