Why is it that the breakpoint does not work?
Show older comments
I define some function. I set a breakpoint in the first line after the function definition statement. But when I run the program the program does not stop at the breakpoint. Why?
10 Comments
Peng Li
on 5 Aug 2020
Did matlab stop anywhere before entering this function? Did you check the command window output? Any error message?
alpedhuez
on 5 Aug 2020
Sudheer Bhimireddy
on 5 Aug 2020
It would help if you could paste your code here.
How are you invoking the live script file?
- Calling it directly from the editor (green "Run" button)
- Calling it from the command window
- Another function / script is invoking it
Does the live script show any warnings or errors within the file?
Have you tried closing the file and reopening it?
alpedhuez
on 5 Aug 2020
alpedhuez
on 5 Aug 2020
alpedhuez
on 5 Aug 2020
Adam Danz
on 5 Aug 2020
Copy-paste the relevant sections into a comment.
alpedhuez
on 5 Aug 2020
Raymond Norris
on 5 Aug 2020
The debugger won't stop in parallel code. Imagine you have a pool of 4 workers and you want to stop on the "c" assignment.
c = 0;
parfor idx = 1:16
A(idx) = rand;
b(idx) = myfcn;
c = c + rand;
end
Where is the breakpoint? For starters, it's not on the MATLAB client because the code is (mostly) running on the workers. But which worker? You have 4 running, all at the same time. So now you'll have 4 breakpoints. This would require a parallel debugger, which MATLAB doesn't have. It's also why when you reverted back to a for loop it worked.
It's best to ensure that the for loop works with out issue (try running your for loop backwards, do you get the same answer) and that you address any Code Analyzer suggestions.
Accepted Answer
More Answers (1)
Steven Lord
on 5 Aug 2020
1 vote
The body of a parfor generally doesn't run in the MATLAB session in which you're running the parfor. As stated in the "Test parfor-Loops by Switching Between Parallel and Serial Execution" example on the documentation page for parfor, "This is the simplest way to allow you to debug the contents of a parfor-loop. You cannot set breakpoints directly in the body of the parfor-loop, but you can set breakpoints in functions called from the body of the parfor-loop."
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!