Using parfor (Matlab) to do parallel computing (CMA-ES Optimization)
2013-03-06
Recently I am testing CMA-ES optimization to tune the parameters of the motion controller for virtual characters, but since the convergence takes such a long time, I am thinking to take full advantage of my six core CPU and make things faster.
In CMA-ES optimization (Matlab code), there is an option for enabling the parallel feature:
opts.EvalParallel = 'yes'
However, this is just an interface, which passes the whole population into the objective function as a NxM matrix (N is the dimension of freedom, M is the number of population). The output of the objective function should be a 1xM array, which returns the fitness of individual.
To utilize the matlab parfor, there are few things to note:
- Global variables are not allowed in the code inside the parfor loop
- Variables declared outside parfor but used inside parfor, must be properly sliced
</ul>
At last, if you can't make your whole program run in parfor, choose the small heavist-computing part and squeeze it into parfor!