parfor problem (broadcast variable)

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);

Antworten (1)

Matt J
Matt J am 18 Sep. 2020
Bearbeitet: Matt J am 18 Sep. 2020

0 Stimmen

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.';

Kategorien

Gefragt:

am 18 Sep. 2020

Bearbeitet:

am 18 Sep. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by