Parfor unnecessary communication overhead

19 visualizaciones (últimos 30 días)
IDN
IDN el 19 de Abr. de 2022
Comentada: IDN el 20 de Abr. de 2022
Hi all,
I have the below parfor loop which is good when I am wanting to pass thru negative values to evaluate. I am getting the following error/warning from MATLAB which I wonder if there is a faster/optimal way to get to the same point improving the below structure.
Error: The Entire Array or Structure "yA_vals"/"yC_vals"/"yD_vals" is a broadcast variable. This might result in unnecessary communication overhead.
yA_vals = -5:5; n_yA = length(yA_vals);
yC_vals = 0:10; n_yC = length(yC_vals);
yD_vals = -10:0; n_yD = length(yD_vals);
parfor yAidx = 1:n_yA
yA = yA_vals(yAidx);
fprintf('>Job 1 %d of %d at %s...\n',yA,yA_vals(end),datestr(now));
for yCidx = 1:n_yC
yC = yC_vals(yCidx);
fprintf('>>Job 2 %d of %d...\n',yC,yC_vals(end));
for yDidx = 1:n_yD
yD = yD_vals(yDidx);
fprintf('>>>Job 3 %d of %d...\n',yD,yD_vals(end));
[~,~,Total(yAidx,yCidx,yDidx)] = Function(Input,yA,yC,yD);
end
end
end

Respuesta aceptada

Raymond Norris
Raymond Norris el 19 de Abr. de 2022
This is a warning, not an error, displayed by the Code Analyzer. Not sure how MATLAB would "throw" this warning.
Depending on the size of the matrix/structure, this could be an issue. Specifically, for large size variables. Of course "large" is relative. But in your case, the vectors are very small -- this won't be an issue for you -- so you can use broadcast variables. To see how much data is being sent back and for, look at ticBytes and tocBytes.
If the variables are large, you could consider a couple of options
  • Create additional variables that represent the portition of the larger variable you need. The Code Analyzer gives an example of this.
  • Create temporay variables (created within the parfor). It's not how you'd write MATLAB serial code, but would avoid the transfer. For example
yA_vals = -5:5; n_yA = length(yA_vals);
parfor yAidx = 1:n_yA
% Create the temporary variable yA_vals in the parfor to avoid the
% transfer.
yA_vals = -5:5;
yA = yA_vals(yAidx);
fprintf('>Job 1 %d of %d at %s...\n',yA,yA_vals(end),datestr(now));
end
  1 comentario
IDN
IDN el 20 de Abr. de 2022
Thanks, this is a great way to understand it!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by