How to resolve warning message about broadcast variable while using 'parfor'?
古いコメントを表示
males = {'animal1', 'animal2', 'animal3'};
treatmentGrps = {'T1', 'T2', 'T3'};
nrows = size(featureLists, 1);
ncols = size(featureLists, 2);
featureLists = cell(nrows, ncols);
parfor grp = 1:nrows
tempRow = cell(1, ncols);
for animal = 1:ncols
tempRow{animal} = individualPsychValuesPerSession('approachavoid', ...
treatmentGrps{grp}, males{animal});
end
featureLists(grp, :) = tempRow;
end
When I use 'parfor' like above I get an warning message
The entire array or structure 'males' is a broadcast variable.
This might result in unnecessary communication overhead.
But, when I change 'ncols' to 'numel(males)' like following
for animal = 1:numel(males)
tempRow{animal} = individualPsychValuesPerSession('approachavoid', ...
treatmentGrps{grp}, males{animal});
end
for the inner loop I don't get any warning.
Can someone please explain this behavior of 'parfor'?
採用された回答
その他の回答 (1 件)
Drew
2024 年 7 月 14 日
編集済み: Walter Roberson
2024 年 7 月 14 日
0 投票
See https://www.mathworks.com/help/parallel-computing/broadcast-variable.html It includes an example with numel().
If this answer helps you, please remember to accept the answer
2 件のコメント
Atanu
2024 年 7 月 14 日
Walter Roberson
2024 年 7 月 14 日
It was due to the ending period being interpreted as part of the URL. I have corrected the link.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!