running parallel optimization problem
Show older comments
Hello
I wrote a function to call a program and optimize its input, the program is working put slow so i thought of using parallel optimization. Then an error appeared that i could not understand.
"Failure in user-supplied fitness function evaluation. GA cannot continue."
The error happens when the FCNVECTORIZER, which is a utility function used for scalar fitness functions.when tries to send the population back to the objective function.
parfor (i = 1:popSize)
y(i,:) = feval(fun,(pop(i,:)));
end
I had not used parallel computing or optimization before. so i need help to solve this issue.
Answers (1)
Walter Roberson
on 28 Jan 2018
For debugging purposes, change the parfor to for and command
dbstop if caught error
and run again. If there is an error, you will be put in the debugger at the place that had the problem.
If no error occurs then you have a problem that is specific to parallel work. If that happens then I would ask whether your code happens to use global variables? The value of global variables are not copied to the workers.
Also you might need to use https://www.mathworks.com/help/distcomp/addattachedfiles.html so that the workers are able to find the function code.
Is your fun possible specified as a string? If it is then change your code to use a function handle: parfor cannot automatically resolve function names that are specified as strings.
6 Comments
Abdulrahman Metawa
on 28 Jan 2018
Walter Roberson
on 28 Jan 2018
Recode to avoid using global variables.
Abdulrahman Metawa
on 29 Jan 2018
Edited: Abdulrahman Metawa
on 29 Jan 2018
Walter Roberson
on 29 Jan 2018
Yes. However when you use the same file names for each worker then the routines are going to interfere with each other.
Abdulrahman Metawa
on 29 Jan 2018
Walter Roberson
on 29 Jan 2018
Not directly, but you can make one and CD there.
td = tempname();
mkdir(td);
cd(td);
Now you can copy in whatever files you need into your current directory.
You might want to add an onCleanup that removes the directory so that the files do not get left around.
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!