How much overhead cost is incurred by using a function handle as a broadcast variable in a parfor loop?

3 views (last 30 days)
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?

Accepted Answer

Matt J
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

Sign in to comment.

More Answers (1)

Edric Ellis
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.

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!