Problem parallelizing a nested optimization problem
Show older comments
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
Answers (2)
Jiro Doke
on 31 Jan 2011
1 vote
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
on 31 Jan 2011
0 votes
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!