How much overhead cost is incurred by using a function handle as a broadcast variable in a parfor loop?
3 views (last 30 days)
Show older comments
I'm trying to parallellize the process of fitting to an (arbitrary) custom function, which I want to be able to specify beforehand:
fitfun = @function
parfor i=1:N
fitparams{i} = fitfun(data(i));
end
However, in the function I'm writing, I get warnings about putting a broadcast variable (fitfun) in a parfor loop. Is this overhead significant or comparable to, say, broadcasting a short vector?
2 Comments
Matt J
on 10 May 2017
The title of your post asks about broadcasting function handles, but your example is about broadcasting fittype objects.
Accepted Answer
Matt J
on 10 May 2017
You'll have to try and find out. It's hard to know how much memory an object or function handle is dragging around with it. For broadcasting anonymous function handles, I wrote this cleaning tool to sift out unwanted memory.
3 Comments
Matt J
on 10 May 2017
I think that should be fine. Only nested and anonymous function handles drag stuff along.
More Answers (1)
Edric Ellis
on 11 May 2017
It's not necessarily a problem to have broadcast data in a parfor loop. If you're using R2016b or later, you can assess the amount of data being transferred to and from the workers using ticBytes and tocBytes.
0 Comments
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!