Parfor unnecessary communication overhead

8 ビュー (過去 30 日間)
IDN
IDN 2022 年 4 月 19 日
コメント済み: IDN 2022 年 4 月 20 日
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

採用された回答

Raymond Norris
Raymond Norris 2022 年 4 月 19 日
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 件のコメント
IDN
IDN 2022 年 4 月 20 日
Thanks, this is a great way to understand it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing Fundamentals についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by