How to fix an error in Parallel Processing?

Dear All,
When I tried to use parfor to run my code, I always got the following error message (I defined the variable "red" at different places but still got this error message):
"An UndefinedFunction error was thrown on the workers for 'red'. This might be because the file containing 'red' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. For more information see the documentation for 'parallel.Pool/addAttachedFiles'.
Caused by:
Undefined function or variable 'red'."
It is weird for me because I tried to define "red" at different place but still cannot fix this problem. Thanks a lot for your great help in advance.
Best regards,
Benson

7 Comments

parfor might be thinking that red is a function instead of a variable. Thta can especially occur if you "poofed" red into existance by defining it in a script, or you used load() without an output argument to define red
Hello, Walter, Thanks for your great help. In my code "red" is just a regular variable and I defined it at the beginning of the code.
Would you please tell me how to define it in a script?
Thanks a lot again.
Benson
I suspect we will need to see your code.
Hello, Walter,
Here is the code of for interation whih is a part of my big code. All variables are correct except "red" which is defined as follows:
red = setdiff([1:length(Ind_mixMI)],tree);
atop = zeros(length(res0), mD);
Flag = zeros(1,mD);
flag = 0;
parfor i = 1 : mD
indrow = lineIndOfftree(i);
deltaHbr = sparse(zeros(length(tree),Nbus));
deltaHrr = sparse(zeros(lengthred,Nbus));
allrowHbr = find(sum(DHbr')>0);
allrowHrr = find(sum(DHrr')>0);
indHbr = [DHbr(indrow,[rowinHbr1 indinbranch1 sign1]);DHbr(indrow,[rowinHbr2 indinbranch2 sign2])];
indHrr = [DHrr(indrow,[rowinHrr1 indinbranch1 sign1]);DHrr(indrow,[rowinHrr2 indinbranch2 sign2])];
[~,rowlocalHbr] = find(DHbr(indrow,[rowinHbr1 rowinHbr2]));
[~,rowlocalHrr] = find(DHrr(indrow,[rowinHbr1 rowinHrr2]));
deltaHbr(indHbr(rowlocalHbr,1),:) = Yf(indHbr(rowlocalHbr,2),IndBus).*indHbr(rowlocalHbr,3);
deltaHrr(indHrr(rowlocalHrr,1),:) = Yf(indHrr(rowlocalHrr,2),IndBus).*indHrr(rowlocalHrr,3);
U = []; V = []; flagUpdateSTop = []; pos = []; flagInvHbrupdate = []; i0 = []; Uncheckline = [];
if nnz(deltaHbr) > 0
tic
res = zeros(lengthred,1);
[res, vtemp, Uncheckline] = func1(Haltmr0, Haltm0, U, V, deltaHbr, deltaHrr, Ind_mixM0, Ind_mixMI0, S0, tree, IndBus, v, res, InvHbr0, flagUpdateSTop, WideBlock, pos, flagInvHbrupdate, vgroup, Uncheckline, i0);
toc
deltares = -res0+res;
[eee, fff] = find(isnan(deltares));
if ~isempty(eee)
deltares = zeros(length(deltares),1);
end
Atoptemp = deltares;
[eee, fff] = find(isnan(Atoptemp));
else
Ires = conj(S0(red)./v0(Ind_mixM0(red,1)))-(Haltmr(red,:)+deltaHrr)*v0(IndBus);
deltares = -deltaHrr*v0(IndBus);
Atoptemp = conj(deltares).*v0(Ind_mixM0(red,1));
end
atop(:,i) = Atoptemp;
end
S0 and Ind_MixM0 are not assigned to in this code. That implies that S0(red) and Ind_MixM0(red, 1) can be precalculated and assigned to variables, and then red would not be needed inside the loop.
I did not copy all the codes in here. S0 and Ind_mixM0 are defined and used in my code. These two variables are key variables and used from the beginning to te end.
Thanks.
Benson
If you cannot post your actual code here, then I think you will need to open a support case. (Which might be needed anyhow, as the solution might not be obvious to the outside volunteers.)

Sign in to comment.

Answers (0)

Tags

Asked:

on 31 Aug 2019

Commented:

on 4 Sep 2019

Community Treasure Hunt

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

Start Hunting!