parfor problems (structure, reduction assignment, etc)
显示 更早的评论
I am attempting to utilize a 'parfor loop' in the code to reduce the time required for the estimation of the "sign restriction vector autoregressive model." The complexity of my sign restriction (=SIGN) results in a lengthy process (more than 24 hours on my laptop) to obtain a sufficient number (ndraws=10000) of successful draws (i.e., those that meet the sign restrictions).
However, I am encountering some difficulties in using 'parfor'. Specifically, the following section of the code, which I would like to apply 'parfor loop', is intended to store the successful draws that satisfy a particular condition (my sign restrictions).
jj = 0; % accepted draws
c1 = 1; % just constant (for counting)
parfor tt = 1:sr_draw
if tt > ndraws
continue
end
% Set up VAR_draw.(draw{j}) for rotations: Only identification uncertainty
label = {['draw' num2str(jj)]};
VAR_draw.(label{1}) = VAR;
% Compute rotated B matrix
B = SignRestrictions(SIGN,VAR_draw.(label{1}),VARopt);
if ~isempty(B)
jj = jj+c1;
% Store B
Ball(:,:,jj) = B;
% Update VAR_draw.(draw{j}) with the rotated B matrix for IR, VD, and HD
VAR_draw.(label{1}).B = B;
% Compute and store IR, VD, HD
[aux_irf, VAR_draw.(label{1})] = VARir(VAR_draw.(label{1}),VARopt);
IRall(:,:,:,jj) = aux_irf;
aux_fevd = VARvd(VAR_draw.(label{1}),VARopt);
VDall(:,:,:,jj) = aux_fevd;
aux_hd = VARhd(VAR_draw.(label{1}),VARopt);
shock(:,:,:,jj) = aux_hd.shock;
end
end
if jj<ndraws
disp('Draws which meet SIGN are not sufficiently stored. Increase sr_draw')
end
1 个评论
Steven Lord
2024-6-21
However, I am encountering some difficulties in using 'parfor'.
What specific difficulties are you experiencing?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!