For loop pauses and restarts randomly
11 ビュー (過去 30 日間)
I have a simple code (below) that contains two for loops. This code computes the power spectrum of a signal and fits a slope to the log-log spectrum.
The code will run and use up about 60% of the CPU for some amount of time, 30 seconds is probably about the max, and then will pause and do nothing for a seemingly random amount of time, sometimes 5-10 minutes or longer before it starts up again and runs for a few seconds. The total run time should only be a few minutes, but it ends up taking hours.
This doesn't happen with only this code, but with other functions inside a for-loop that will utilize more then one processor at a time such as 'imfilter'. It will also happens when I run the code as a function or in the command window.
I am running Matlab r2011b on a 12-core Intel system.
If anyone has any idea what I could do so that the program does not pause please let me know.
the cyclist 2012 年 5 月 1 日
Without looking at your code in detail, I can say that that behavior is typical of what happens when the memory needed by your code transitions from RAM into virtual memory. The bottleneck becomes the memory access, so the CPU usage drops radically. You might want to look at memory usage.
(I don't have the signal processing toolbox, so I can't investigate more.)
その他の回答 (1 件)
Ed Callway 2021 年 9 月 2 日
Fascinating - I have the same issue in 2021! Programs just stall randomly.
- Win 10 up to date, 4TB SSD with a ton of space, 32 GB DRAM, 6 core 12 thread Ryzen 3600X, no overclocking or BSOD, monitoring speed and temps and fans fine, multi-day borrowed license for offline work, internet disconnected to avoid distractions.
- Running 6 copies of a single script in 6 instances of matlab R2020b from a batch file like this:
- matlab /r "someScriptName (parameterSet1a, parameterSet1b)"
- matlab /r "someScriptName (parameterSet2a, parameterSet2b)" etc etc to set 6a&b
- Matlab app writes nothing to disk till it finishes, so disk idle
- Those 6 copies of everything using just 7GB of 32 GB, no memory thrashing
- Total CPU load ~66%, each matlab process taking about 10%, command windows printing out progress, all well and good
- The script contains loops doing fairly normal math, and one of the loops does use parfor (gives about a 10% speed boost)
- At the end of one of the bigger loops (about once a second) it does a tik tok to print out time elapsed and estimated finish time
Runs fine for about 5 hours out of the 24 it needs, then every 10 minutes or so the 6 instances stop one at a time about 10 seconds apart, stop printing to command window, and their CPU usage each drops to 0%.
- After a minute or 2 they start up again one at a time and run fine for about another 10 minutes.
- Note from Task Manager I know the order they were started in. They ALWAYS stop running starting from the last one started (hours ago), progressing to the 1st one started. When they start up again it's also always in that same order.
- I can start CPU-Z and run an all core stress that pushes the CPU to 100% and drops the matlab load to 50%. Temps remain fine, doesn't affect the matlab copies, running or stalled.
- I can manually start and run another matlab instance when the other 6 are stalled and it's fine
- Any other program I start when the matlabs are idled runs fine too.
- Renabling the network, running a browser etc also makes no difference
So I see nothing on power, voltage, temps, network, cpu load, disk or memory load that looks bad...except matlab randomly sleeps.
The code itself is long and proprietary, can't put it up here. Would love to hear things to avoid, other similar stories with clues, or tiny cut down scripts to try.
As Leeloo Dallas said, plz halp