Why is it that the breakpoint does not work?
Mostrar comentarios más antiguos
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 comentarios
Peng Li
el 5 de Ag. de 2020
Did matlab stop anywhere before entering this function? Did you check the command window output? Any error message?
alpedhuez
el 5 de Ag. de 2020
Sudheer Bhimireddy
el 5 de Ag. de 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
el 5 de Ag. de 2020
alpedhuez
el 5 de Ag. de 2020
alpedhuez
el 5 de Ag. de 2020
Adam Danz
el 5 de Ag. de 2020
Copy-paste the relevant sections into a comment.
alpedhuez
el 5 de Ag. de 2020
Raymond Norris
el 5 de Ag. de 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.
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 5 de Ag. de 2020
1 voto
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."
Categorías
Más información sobre Parallel for-Loops (parfor) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!