Using broadcasting array variable values as indexes

4 vues (au cours des 30 derniers jours)
Farbod Tavakkoli Khomeini
Farbod Tavakkoli Khomeini le 18 Oct 2019
I am using parallel tool for running my code. Actually there is no major error and the code runs but I have some minor error such as "The entire array or structure 'AccelerationY' is a broadcast variable. This might result in unnecessary communication overhead". I have the same error in my code in four different places which I have indicated below with # in bold.
My first question is how can I solve this problem in my code. Second, does it really hurt the runtime of the code?. Because my code has a very high runtime.
I appreciate your kind help in advance,
carnum = data{1,1};
AccelerationY = data{1,2};
coordinationx = data{1,3};
coordinationy = data{1,4};
velocity = data{1,5};
parfor j=1:car
x{j}=[];
y{j}=[];
speed{j}=[];
AccX{j}=[];
AccY{j}=[];
z_gyro{j}=[];
f=find(carnum == j);
for a=f
x{j} = [x{j},coordinationx(a,1)]; %#here for coordinationx
y{j} = [y{j},coordinationy(a,1)]; %#here for coordinationy
AccY{j} = [AccY{j},AccelerationY(a,1)]; %#here for AccelerationY
rr= velocity(a,1)/3.6; %#here for Velocity
speed{j} =[speed{j},rr];
end
end

Réponse acceptée

Walter Roberson
Walter Roberson le 18 Oct 2019
In that code you cannot eliminate the broadcast variables.
If the arrays are large then there could potentially be a fair overhead in copying them into each worker.
You can, however, rewrite the entire code without parfor, by using a series of accumarray() or splitapply() calls, or you could switch to table representation and use table operations.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by