Slice Broadcast Variables in Parfoor Loop - Index Problems
이전 댓글 표시
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.
답변 (1개)
Walter Roberson
2016년 7월 2일
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
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!