Difference between debug parfor loop and run it

8 views (last 30 days)
Hello everyone,
I have the following question: Whats the differnce between debugging a parfor loop and run it? In the matter that i stop executing the code before the parfor loop and then execute the hole parfoor loop with pressing F9.
Because, if i debug the parfor loop it can be execute without any error but if I run it normally the following error message appears:
"for the parfor-loop that is trying to execute on the worker could not be found."
and
"Caused by:
Unrecognized function or variable 'A'.
Error using remoteParallelFunction (line 94)
Worker unable to find file.
Unrecognized function or variable 'A'."
Before the parfor-loop gets called other function gets called and the parfor-loop is also calling a other function. The called function makes some calculation and saving stuff to the file system, nothing else. So I am a bit confused, because variable 'A' is a variable that isn't changed and every iteration gets variable A.
Thanks for the help already!
  3 Comments
Nicolas Kaiser
Nicolas Kaiser on 27 May 2022
Okay I have the following code:
parfor i = 1 : n
fcn_do_something(A(i),copy(B),copy(C),D,F);
end
Before this lines there is code and after this lines. The function "fcn_do_something" is performing some calculations based on A,B,C,D,F. It have no output argument. If I now set a breakpoint directly before the parfor loop and select the three lines of the loop with the cursor and press then F9 to excecute the selected lines the code is running without an error message. But if I a excecute the hole code normaly, without breakpoint and partial debugging, its ending with the error message above. Its the same code so I am really confused how MATLAB can read this differently.
Unfortunately, I cannot provide the other code as well, since I am not authorized to do so. I hope thats enough to understand my problem.
Nicolas Kaiser
Nicolas Kaiser on 27 May 2022
Error message: The source code (PATH TO CALLING FUNCTION) for the parfor-loop that is trying to execute on the worker could not be found.
It seems to be this problem but I can't really interprete this.

Sign in to comment.

Accepted Answer

Edric Ellis
Edric Ellis on 27 May 2022
Further to Walter's answer, parfor assumes that anything that is not statically provable to be a variable reference must be a function reference. In your case, I suspect you're using eval or load to generate the variables A etc. The parfor machinery is therefore unable to transfer A to the workers, and instead assumes A is the name of a function - which it then can't find. Here's a simple example which shows the problem:
doStuff();
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 2). Analyzing and transferring files to the workers ...done.
Error using solution>doStuff
The source code (solution.mlx) for the parfor-loop that is trying to execute on the worker could not be found.

Caused by:
Undefined function 'A' for input arguments of type 'double'.
Error using remoteParallelFunction
Worker unable to find file.
Undefined function 'A' for input arguments of type 'double'.
function out = doStuff()
eval('A = 1;');
parfor i = 1
out(i) = A(i);
end
end
If this is indeed the problem, then the fix is simple: don't use load or eval - ensure the variables are defined in the text of the program normally.

More Answers (2)

Walter Roberson
Walter Roberson on 27 May 2022
parfor is not always able to automatically determine which functions will be called by workers, especially if eval() or run() is used or if you have calls to an optimization or ode* function that uses a quoted string for the function name instead of using a function handle.
In order to tell parfor where to find the files you may need to attach them to the pool.
Over the longer term, if you are using quoted strings for function names you should probably rewrite to use anonymous functions.
https://www.mathworks.com/help/parallel-computing/parallel.pool.addattachedfiles.html

Nicolas Kaiser
Nicolas Kaiser on 30 May 2022
Thanks both of you! The problem was that used load to get some of the input variables for the function.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!