Borrar filtros
Borrar filtros

UNDEFINED VARIABLE OR FUNCTION

1 visualización (últimos 30 días)
Homayoon
Homayoon el 25 de Feb. de 2016
Comentada: Walter Roberson el 27 de Feb. de 2016
Hello--
I am using the parallel toolbox which cause me to see this error message:
An UndefinedFunction error was thrown on the workers for 'Q'. This might be because the file containing
'Q' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to
be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Caused by:
Undefined function or variable 'Q'.
The structure of my code is as following:(You can see how I defined Q)
DS=[is a given 1*N matrix]
parfor s = 1 :size(1,DS)
% with some commands I end up having a new matrix called V
for j = 3:2:( 2*(size(V,1))
if ((V(j,1) - V((j-2),1)) ~=0)
vicinity_atom = [(V(j,:)), ( V((j-2),:)) 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
reduced_vicinity_atom = (sortrows((unique(vicinity_atom(vicinity_atom ~= 0),'stable')).')).' ;
n = size (((find (reduced_vicinity_atom <(nh+1))).'), 1);
m = size (((find (reduced_vicinity_atom >(nh))).'), 1);
Q = zeros ( 501 ,( (1.5*(n+m))+ 6)); %This is where I defined matrix Q!
Q(1:28 , ( (1.5*(n+m))+ 6)) = vicinity_atom' ;
%Here I am proposing some calculations to fill the matrix Q with appropriate values
tttt = k + (1*285000);
output = sprintf('%d%s%d.csv',tttt,'evolution',atom);
dlmwrite(output, Q, 'delimiter', ',', 'precision', 9);
end
end
end
Thus, in the parfor loop there is a for loop in which a matrix Q is generated for the identifiers which satisfy the if conditions. As you see I saw such an error which would not be happened if I change parfor to for. Can anyone explain the reason and suggest a way to tackle this issue?
Thanks

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Feb. de 2016
The code has no way of proving that ((V(j,1) - V((j-2),1)) ~=0) will be true exactly once. parfor needs it to be obvious that all variables are well defined.
If there are more than one ((V(j,1) - V((j-2),1)) ~=0) then you are overwriting Q: are you sure you want to do that?
If you are certain that there is exactly one matching case perhaps you should use find() instead of a loop to locate it. Whether you do that or not, consider dlmwrite'ing within the section that defines Q.
  16 comentarios
Homayoon
Homayoon el 27 de Feb. de 2016
Would you please specifically determine in what line of my code I have to add 'clear' statements? I am confused and totally lost Thanks
Walter Roberson
Walter Roberson el 27 de Feb. de 2016
"Please be advised, as stated earlier the code runs perfectly and produces desirable outputs if I change parfor to for. "
I express my doubts about that. I think that some of your paths do not initialize some variables. Each parfor worker is a separate process, and tasks can be assigned to different workers at arbitrary "parfor" indices, so if any variable is not defined in one path then the variable might not exist in the worker (or might, depending what the worker has happened to have done previously.) The way to debug that behavior while using "for" is to add a whole bunch of "clear" and see if the code bombs on the larger file.
Or you could use the debugger on the parfor version, perhaps putting in a breakpoint conditional on that array not existing, and when it fires work backwards to figure out why. I have not attempted to debug parallel processes so I do not know what the limitations of doing so are.

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel for-Loops (parfor) 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