parallel computing in Genetic algorithm

26 visualizaciones (últimos 30 días)
Ashok Das
Ashok Das el 2 de Sept. de 2021
Comentada: Ashok Das el 3 de Sept. de 2021
Hello everyone,
I am using the genetica algorithm code 'ga' to optimize my function. However, it is taking very large amount of simulation time.
I have tried adding the "'UseParallel',true" inside the gaoptimset. But now, the code is getting stopped after the first iteration.
Please help me to solve it.
Thanks in advance.

Respuestas (2)

Alan Weiss
Alan Weiss el 2 de Sept. de 2021
You have to be careful using parallel computing. Are you using Simuulink® for the simulation? I am not sure that it can run in parallel inside ga because ga uses a parfor call, not a parsim call. If you are using a different software package to run the simulation, you have to ensure that it can run in parallel. If you have any global variables, well, you cannot run the simulation in parallel.
Are you sure that ga is the best optimizer for you? Can you try patternsearch or surrogateopt?
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 comentarios
Alan Weiss
Alan Weiss el 3 de Sept. de 2021
If you want to run in parallel then you have to get rid of any global variables. They are a bad idea in any case. If you use them to pass data or parameters, stick the data in a structure called params and pass params as extra data; see Passing Extra Parameters. For example, to pass an array A and a vector B,
params.A = A;
params.B = B;
% Then in your objective function
function y = objfun(x,params)
A = params.A;
B = params.B
% Now put in the rest of your code
end
% You call the objective like this:
fun = @(x)objfun(x,params)
[x,fval] = patternsearch(fun,...)
I suggest that you use patternsearch as a much more efficient solver than ga. You have to set the CompletePoll option to 'on' to use parallel processing with patternsearch.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Ashok Das
Ashok Das el 3 de Sept. de 2021
Thanks Alan for your reply.
I have eliminated the global variables.
I will try it with paramsearch with CompletePoll option. I will notify whether it is working or not.

Iniciar sesión para comentar.


John D'Errico
John D'Errico el 3 de Sept. de 2021
Editada: John D'Errico el 3 de Sept. de 2021
Whenever I see someone say they need to use parallel computing to make their code run faster, I wonder if the real problem is they just need to learn to write better, more efficient code. Hoping for parallel computing to make your code magically run fast is the lazy solution. Why improve your code? Just wave a magic wand at it.
This conclusion is made more likely when I see you are using global variables as a means to pass things around. Globals are a poor tool, used mainly by novice programmers in MATLAB. And that alone tells me you can surely write better code. How much better? It is easy to get orders of magnitude speed bumps, just by writing better code. Do I know this to be true in your code? Of course not, since I have not seen your code, nor will I be willing to spend what may be a lot of time to rewrite your code.
The idea is to start with the profile utility in MATLAB. See where the bottlenecks are. What lines are using the most time? Then focus your efforts on those lines. Can you improve them? Sometimes this will require a complete re-thinking of what you are doing, changing how you will solve the problem.
is that a likely thing to happen? Yes, i know it to be entirely possible, since I personally had some code that I wrote and re-wrote as I was learning MATLAB long ago, achieving speed boosts of many orders of magnitude along the way.
  1 comentario
Ashok Das
Ashok Das el 3 de Sept. de 2021
Knowledge is a beautiful thing. You earn it to spread to others. However, you need to make sure that you don't behave like a troll or nerd, who thinks that others know nothing.
I already mentioned that I am not an expert in this field. So used global parameters. Other than this, the code is a iterating simulation of some physical phenomenon with very small time step. The problem is not the bottleneck, it is the number of iterations, which is taking very large time. So, if you remove also the unnecessary things, it will not much be of an help in terms of run time. (FYI, there exist many softwares like EDEM and others which does simulate 1 sec of process in some days)
Then also, thanks for your reply.

Iniciar sesión para comentar.

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by