Using broadcasting array variable values as indexes
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!