Slice called broadcast variable in parfor

5 views (last 30 days)
I have a code I want to parallelize, something like:
parfor i = 1:length(all_idx(:,1))
combis = nchoosek(1:k,2);
results = zeros(length(combis(:,1)),1);
for j = 1:length(combis(:,1))
results(j) = fun(X(:,all_idx(i,combis(j,1))), X(:,all_idx(i,combis(j,2))));
end
...
end
X and all_idx are broadcast variables, especially X is a huge matrix and produces a significant overhead. I read something about slicing the variables, the computation results are strored in (variables in which I write), but is there a way to somehow slice the variables which are read within the loop? As far as I understand, the whole matrices X and all_idx have to be sent to every worker in order to extract the columns needed, or did I miss something?
  2 Comments
Edric Ellis
Edric Ellis on 18 Dec 2019
It looks from your code very much like each iteration of your outer parfor loop needs the whole value of X available. In this case, it is unavoidable that X must be sent separately to each worker.
"Slicing" variables is good - when it works - i.e. when your parallelism can be expressed as operations over independent "slices" of your data
Mariella Dreißig
Mariella Dreißig on 18 Dec 2019
Okay thanks, then I got it right and I can't do anything against this broadcast variable.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!