How can I degug inside a parfor loop?

36 visualizaciones (últimos 30 días)
Farook Sadarudeen
Farook Sadarudeen el 26 de Oct. de 2017
Respondida: zhehao.nkd el 5 de Ag. de 2022
When I insert breakpoints inside a parfor loop it is never stopped. In this case how can I debug inside a parfor loop?
  2 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 26 de Oct. de 2017
Please show your code, have you use break statement within parfor loop with a condition?
Check it out, it may be helpful
https://in.mathworks.com/matlabcentral/answers/4942-break-in-a-parfor-loop-processing-time-example-to-compare-it-with-a-for-loop

Iniciar sesión para comentar.

Respuesta aceptada

Edric Ellis
Edric Ellis el 30 de Oct. de 2017
You can debug code called from the body of a parfor loop if no parallel pool is open, but unfortunately you cannot debug the body of a parfor loop itself. You can force the parfor loop to run in the desktop MATLAB by appending the optional "number of workers" argument, like so:
parfor (idx = 1:10, 0)
out(idx) = myFcn(idx);
end
With that code, you can set breakpoints inside myFcn.
  1 comentario
Farook Sadarudeen
Farook Sadarudeen el 1 de Nov. de 2017
Thanks for the answer. This helps to Debug.

Iniciar sesión para comentar.

Más respuestas (2)

NAGAVARSHINI MAYAKKANNAN
NAGAVARSHINI MAYAKKANNAN el 21 de Jun. de 2020
Change the parfor to for debug it and then change for to parfor

zhehao.nkd
zhehao.nkd el 5 de Ag. de 2022
For those who are seeking for the solution, there is another possible option by using parfor and try-catch:
parfor k = 1: len
try
% your code
catch ME
% record the iteration index,k
end
end
% Then youy know which iteration caused a bug alert

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by