MATLAB Answers

Parallel computing for genetic algorithm

21 views (last 30 days)
Ugur Acar
Ugur Acar on 1 Jun 2020
Commented: Ugur Acar on 1 Jun 2020
i have an objective function that calls an external program for optimization work. Running and getting results of objective function is very time consuming since the external program works really slow.
i want to distrubute the population generation task to 4 workers. But every worker must first copy the objective function folder which has an external function files in it into a seperate folder and then run the external program in that folder. this way, external program doesnt confused since it works seperately.
im using this file:
it has this code in evaluate.m file for parallel computing;
parfor i = 1:N
fprintf('\nEvaluating the objective function... Generation: %d / %d , Individual: %d / %d \n', state.currentGen, opt.maxGen, i, N);
[pop(i), allTime(i)] = evalIndividual(pop(i), opt.objfun, varargin{:});
function [indi, evalTime] = evalIndividual(indi, objfun, varargin)
[y, cons] = objfun( indi.var, varargin{:} );
What should be done in parfor loop above in order to create seperate working folder that has a copied external program files in it for each worker ?
thank you


Alberto Mora
Alberto Mora on 1 Jun 2020
Honesty I don't know to do what you want, but one possible solution to speed-up genetic algorithm optimization, is to use "vectorized" population.
Ugur Acar
Ugur Acar on 1 Jun 2020
Alberto Mora thank you for your answer. you are right i may not explain the problem clearly.
My objective funtion calls an external program. if each worker calls the objective function at the same time,it cannot evaluate objective function. so, before the worker call the objective function in parfor loop, objective function folder must be copied and the worker should work in that seperate folder.
Ugur Acar
Ugur Acar on 1 Jun 2020
i created 4 folders and copied necessary external program files into these folders before running optimization algorithm. Let say folder names are worker1,worker2, worker3 and worker4.
I have quadcore machine and i want 4 parallel jobs at the same time.
how sud i make sure each worker evalute the objective function in differents folders (worker1,worker2, worker3 and worker4 folders)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by