Using broadcasting array variable values as indexes

조회 수: 3 (최근 30일)
Farbod Tavakkoli
Farbod Tavakkoli 2019년 10월 18일
편집: Walter Roberson 2019년 10월 18일
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

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 18일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by