Using broadcasting array variable values as indexes

4 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Oct. de 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.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by