Slice Broadcast Variables in Parfoor Loop - Index Problems
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I tried to speed up the following code by using a parfor loop
parfor i = 1:Nr
[F_OIS] = mcSimNr(tg,dt,tgT,tr,q,maxTenor,H,F0_OIS,T);
for j = 1:size(MatTenor,1)
VswapMC(i,j) = Swap(M,tr,K(j),w,F_OIS(:,indextgT(j)),B0,indexs(j),indexe(j),maxTenor);
end
end
where K, indextgT, indexs and indexe have dimensions size(MatTenor,1)x1. In the nested forloop of a particular loop of the parfor loop, all the elements of those arrays are used.
I get a warning message in Matlab saying that those variables are broadcast variables and a suggestion that I should try to slice them.
However, is this necessary in this case since, in my opinion, the whole arrays have to be sent to each worker since in each iteration of the parfor loop they are used as a whole? If not, does anybody have any suggestions how I could slice them?
Any help is appreciated. Thanks in advance.
0 Kommentare
Antworten (1)
Walter Roberson
am 2 Jul. 2016
I would expect that code to error. The adjusted code would be more like
MTLen = size(MatTenor,1);
VSclass = class(VswapMC);
parfor i = 1:Nr
[F_OIS] = mcSimNr(tg,dt,tgT,tr,q,maxTenor,H,F0_OIS,T);
Vswapj = zeros(1, MTLen, VSclass);
for j = 1 : MTLen
Vswapj(1,j) = Swap(M, tr, K(j), w, F_OIS(:,indextgT(j)), B0, indexs(j), indexe(j), maxTenor);
end
VswapMC(i, :) = Vswapj;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!