running parallel optimization problem
Mostra commenti meno recenti
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.
Risposte (1)
Walter Roberson
il 28 Gen 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 Commenti
Abdulrahman Metawa
il 28 Gen 2018
Walter Roberson
il 28 Gen 2018
Recode to avoid using global variables.
Abdulrahman Metawa
il 29 Gen 2018
Modificato: Abdulrahman Metawa
il 29 Gen 2018
Walter Roberson
il 29 Gen 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
il 29 Gen 2018
Walter Roberson
il 29 Gen 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.
Categorie
Scopri di più su Parallel for-Loops (parfor) in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!