Hi all<div>I want to use GAlib to solve a huge problem and as a result, I have to run it in parallel.</div><div>Actually the evaluation of the objective function is the most time consuming part in my code. (Evaluation of each genome/individual will take about 2 secs). </div>
<div>I thought it may be helpful to evaluate different individuals in a population in parallel to improve the total simulation time.</div><div>I decided to test if I can use OpenMP . So I modified the GAPopulation.cpp file as below</div>
<div><br></div><div>Original code:</div><div><div>GAPopulation::DefaultEvaluator(GAPopulation & p){</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for(int i=0; i<p.size(); i++){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>p.individual(i).evaluate();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>}</div></div><div><br></div><div><div>Modified code:</div><div><div>GAPopulation::DefaultEvaluator(GAPopulation & p){</div><div> #pragma omp parallel for num_threads(64) // I am using 64 threads</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>for(int i=0; i<p.size(); i++){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>p.individual(i).evaluate();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>}</div></div></div><div><br></div><div>And the results were shocking!!</div><div>During evaluation of the first generation, the evaluator runs in parallel and uses all 64 available threads. But for the rest of the simulation, it only uses 4-5 of the threads.</div>
<div><br></div><div>Another wired thing is that this problem only happens if I use GASteadyStateGA or GAIncrementalGA. But if I chang to GASimpleGA, I will not have this problem and the simulation uses all 64 available threads.</div>
<div><br></div><div>Any idea what is causing this problem and how can I solve it?</div><div><br></div><div>Cheers,</div><div>Sina</div>