Azzera filtri
Azzera filtri

How to resolve warning message about broadcast variable while using 'parfor'?

27 visualizzazioni (ultimi 30 giorni)
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'?

Risposta accettata

Edric Ellis
Edric Ellis il 15 Lug 2024 alle 12:09
I think you should ignore this message in this case. It looks like you really need all the values of males for each iteration of the parfor loop, and that's OK. The message is there to warn about cases where the data is being "accidentally" broadcast.
The fact is that the array males is very small (in terms of bytes), so it should not cause significant overhead. You can check using whos to see the size of the array in the workspace, and also use ticBytes and tocBytes to see how much data is being transferred to run the loop. My bet is that the overall data transfer is not being significantly changed by the size of males.

Più risposte (1)

Drew
Drew il 14 Lug 2024 alle 21:54
Modificato: Walter Roberson il 14 Lug 2024 alle 22:44
If this answer helps you, please remember to accept the answer
  2 Commenti
Atanu
Atanu il 14 Lug 2024 alle 22:23
Thanks for your response. But the link is not working for me.
'The page you were looking for is not available in this version of the documentation. You can use the search box or browse the products to find related information. You can also view archived documentation for prior releases.'
Can you share the link again?
Walter Roberson
Walter Roberson il 14 Lug 2024 alle 22:44
It was due to the ending period being interpreted as part of the URL. I have corrected the link.

Accedi per commentare.

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by