Matlab gets stuck - No error message
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear All,
I am stuck with a real problem. I have written a script (please see blow the summary) that works well, but sometimes for no apparent reason it gets stuck. I firmly say it is not an endless loop.
I would be very thankful if you provide me with any suggestions, as I tried many and it didn't work. The main reason that I can think of is that the problem could be associated with the RAMs! Especially when the number of iterations within the while loops become large. If this is the case, is there a way to keep refreshing the memory?
Kindly note that the machine I am using is QuadCore, Intel Xeon® @ 2.4 GHz, 64 GB Rams
Since I already started the post; does anyone know a way that makes this simulation faster? (any hints, or toolbox that does the trick)
Thanks Experts, I really appreciate your help.
%script - kindly note that afterwards, I export the results to excel
%defining No of Simulations & the steps
ii = 10000000;
Min = 100;
Max = 110;
Steps = 1;
Observations = ((Max - Min)/Steps)+1;
PriceVector = Min:Steps:Max;
%Defining Parameters
...
...
StartingTime=0;
StartingDay=0;
EndingDay=20;
...
...
%Creating Matrices for speeding up the process
frequency = zeros(ii,Observations);
Count = zeros (ii,Observations);
DayX = zeros(1,Observations);
DayY = zeros(1,Observations);
SurV = zeros(1,Observations);
ONX = zeros(1,Observations);
PriceVec = zeros(1,Observations);
%Initiating the progress bar
multiWaitbar('Main for loop',0,'Color', 'b'); %progress bar of #Ben Tordoff.
multiWaitbar('Sub for loop',0, 'Color', 'g');
for j=1:Observations
values = zeros(1,ii);%to speed up the process
Incremental=PriceVector(j);%this gets the next incremental value
for i=1:ii;
StockPrice=Incremental;
Days=StartingDay; %start day
Hours=StartingTime;
knockout = 0; %This variable will terminate the while loop when false
while knockout == 0
%some calculations
knockoutNew = 0;
while (knockout == 0 && knockout2 == 0)
%some calculations
Hours = Hours + SS %SS is the sampling interval
if true %first condition
value = 0;
knockout = 1;
elseif true %sub condition
knockout2 = 1;
end
end
if true %first condition - Breaking the first while loop since the condition is met in the sub loop
break
end
if Hours < 1
%some calculations
if true %second condition
value = 0;
knockout = 2;
end
else
if Days==EndingDay; %third condition
value = 5;
knockout=3;
else
%some calculations
if true %fourth condition
value = 0;
knockout = 4;
else
Days=Days+1; %this ensure the termination of the loop
Hours = 0;
end
end
end
end
values(i) = value; %gets the values of the knockout i.e, either zero or 5
frequency(i) = knockout;
%progress of the sub for loop
multiWaitbar('Sub for loop',i/ii);
end
Kvalue=%somecalulations;
kboV(j)=KBO;
%collecting the count of each case of each price element
DaytimeKO(j)=sum(histc(frequency,1));
DayJumpKO(j)=sum(histc(frequency,2));
Survival(j)=sum(histc(frequency,3));
ONightKO(j)=sum(histc(frequency,4));
PriceVec(j) = Incremental;
%progress of the main for loop
multiWaitbar('Main for loop',j/TotalProcess);
end
0 commentaires
Réponses (1)
dpb
le 23 Sep 2013
I firmly say it likely (given the pseudo-code if...end conditional blocks above) IS occasionally finding a set of conditions that are an infinite loop.
Memory refresh is a hardware-implemented feature of the machine; that or similar things is not in any way at all a feasible/likely cause for your problem, it is almost certainly a logic problem for a certain set of data inputs.
There's insufficient detail to tell for certain but I'd suspect if one had the overall actual code one could vectorize the loop and logic almost if not entirely from the way it appears structured overall.
4 commentaires
dpb
le 24 Sep 2013
Modifié(e) : dpb
le 24 Sep 2013
The problem only occurs, when I run another process(s) without restarting Matlab....
So, the problem likely isn't Matlab at all, iow.
I still think you should look at restructuring your code and vectorizing it extensively and would find marked improvement in performance if did so...
ADDENDUM:
I pasted your code in the editor w/ the intent of trying to actually look at the above but the missing conditionals even w/ the incomplete description you added make doing anything useful impossible as far as seeing how vectorization might solve your problems. :(
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!