running parallel optimization problem

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)

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

well my function uses a global variables but how to pass the to workers
can the worker execute a dos commands:
dos('copy input.dat runningin.dat')
dos('reader runningin tmp.zzz')
dos('solver runningin tmp.zzz')
dos('rename runningin.num input.num')
dos('rename runningin.nod input.nod')
dos('del runningin.*')
Yes. However when you use the same file names for each worker then the routines are going to interfere with each other.
can i specify the directory in which each worker can operate
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.

Sign in to comment.

Categories

Products

Asked:

on 28 Jan 2018

Commented:

on 29 Jan 2018

Community Treasure Hunt

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

Start Hunting!