How to find function and variable value at each iteration for genetic algorithm with Parallel Computing ?
Show older comments
Hello everyone,
I have prepared code in matlab for genetic algorithm from toolbox for number of iteration (nit)
for i=1:nit
[x,fval,exitflag,output,population,score] = GAcode(nvars,lb,ub,InitialPopulationRange_Data,PopulationSize_Data,EliteCount_Data,CrossoverFraction_Data,MaxGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data);
H1(i,1)=fval;
H2(i,1:nvars)=x;
end
where at the end H1 and H2 gives function and variable value for all the iterations respectively. 'GAcode' is file generated from toolbox. The code works properly.
I am trying to use parallel computing for increasing speed. Firstly started parallel pool and in preferences defined number of workers as 8. In file 'GA code' i have given
options = optimoptions(options,'UseParallel', true);
While using, parfor for i=1:nit, following error is obtained "Unable to classify the variable 'H2' in the body of the parfor-loop." If i remove H2 code runs properly.
How can i obtain H1 and H2 value after each iteration with parallel computing ?
For current setup even when the "for" loop for number of iterations is removed and done for single iteration no speed improvement is observed in parallel computing applying above options rather with parallel it is 63 sec and without it is 58 sec. The results are ok. What am i doing wrong ?
Thanks for your help.
Accepted Answer
More Answers (0)
Categories
Find more on Parallel Computing Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!