Problem parallelizing a nested optimization problem

Dear all,
I am having trouble parallelizing the following nested optimization problem. In the upper level nest I maximize a function, in search for the optimal parameter vector (c_par). Each iteration of this upper level optimization level involves a series of 132 (potentially more) independent optimization problems. Since running the program serially takes a very long time, I've been trying to parallelize the lower level optimization problems with PARFOR loops.
I keep getting the following error: A parfor body cannot refer to a nested function (foc_par1).
Here's what I'm doing, and maybe anyone has suggestions that can help me solving this in parallel:
Upper level optimization called from upperlevel.m
[cpar_ols, fval, exitflag] = fminunc('conf_game_par_new', cpar_start, options1);
The m-file conf_game_par_new.m then does several things (given a vector of parameters c_par):
start=0;
parfor s=1:132
%%A block of data transformations and setup of the s-optimization problem
e_init = par;
cost_par = Alpha_p(1:5);
Alpha_init = 0.2.*ones(n,1)';
[Alpha] = fminunc(@foc_par1, Alpha_init, options);
end
Here's where I get my problem, since the function foc_par1 used in the lower level optimization problem for each iteration s, and is defined at the same in the same m-file.
I'm not sure what to do here.
Thanks in advance.
Daniel

Risposte (2)

Jiro Doke
Jiro Doke il 31 Gen 2011
That happens to be one of the restrictions for PARFOR. You should either make function foc_par1 a subfunction or a separate function MATLAB file.
Daniel
Daniel il 31 Gen 2011
Hi Jiro, thanks for your reply. It appears to be working now. I believe that the problem was on how to handle each s-specific data, which I ended up passing as extra parameters.
Thanks, Daniel

Richiesto:

il 30 Gen 2011

Community Treasure Hunt

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

Start Hunting!

Translated by