- 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.
parfor problems (structure, reduction assignment, etc)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
inani2011
am 21 Jun. 2024
Beantwortet: Edric Ellis
am 25 Jun. 2024
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 Kommentar
Steven Lord
am 21 Jun. 2024
However, I am encountering some difficulties in using 'parfor'.
What specific difficulties are you experiencing?
Akzeptierte Antwort
Edric Ellis
am 25 Jun. 2024
The problem here is that you're trying to extend the arrays like Ball by assigning off the end of the current size of the array. You cannot do that in parfor. What you can do is use concatenation, a bit like this:
Ball = zeros(7, 7, 0); % Or whatever size is appropriate
cat3 = @(x, y) cat(3, x, y); % Function to use as reduction operation
parfor tt = 1:sr_draw
B = SignRestrictions(SIGN,VAR_draw.(label{1}),VARopt);
if ~isempty(B)
Ball = cat3(Ball, B)
end
end
Note that I needed to make a simple function to ensure that I could write a parfor reduction operation.
You should be able to apply the same pattern to the other problematic assignments.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!