Mode_compute = FUNCTION_NAME

Dear all,
I want to integrate parpool command in a function that will be called in mode_compute. I want to do this in order to use Parallel Computing Toolbox for computing the mode.
I took the idea from:

Please could you help me, to write inputs and outpus of this “function_name”? I am thinking it could be like this:

function y = function_name;

dum = 1;

tic
if dum == 1
parpool
y = fminunc(???);
end
toc

% p = gcp 
delete(gcp)

end

Please have a look at the fs2000_w.mod and the optimizer_function_wrapper.m at https://github.com/DynareTeam/dynare/tree/master/tests/optimizers

Thank dear jpfeifer,

I used the function of the example, optimizer_function_wrapper and it works well, but when I use my function I get this error message:

Initial value of the log posterior (or likelihood): -20760.1563
Reference to non-existent field 'analytic_derivation'.

Error in dsge_likelihood (line 150)
analytic_derivation = DynareOptions.analytic_derivation;

Error in fminsearch (line 190)
fv(:,1) = funfcn(x,varargin{:});

Error in my_optimizer_function_wrapper (line 13)
[opt_par_values,fval,exitflag] = fminunc(objective_function_handle,start_par_value,varargin{:});

Error in dynare_minimize_objective (line 505)
            [opt_par_values, fval, exitflag] = feval(minimizer_algorithm,objective_function,start_par_value,varargin{:});

Error in dynare_estimation_1 (line 220)
    [xparam1, fval, exitflag, hh, options_, Scale, new_rat_hess_info] =
    dynare_minimize_objective(objective_function,xparam1,options_.mode_compute,options_,[bounds.lb
    bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);

Error in dynare_estimation (line 105)
    dynare_estimation_1(var_list,dname);

Error in ls (line 270)
oo_recursive_=dynare_estimation(var_list_);

Error in dynare (line 223)
evalin('base',fname) ;

My function is:

function [opt_par_values,fval,exitflag]=my_optimizer_function_wrapper(objective_function_handle,start_par_value,varargin)
% function [opt_par_values,fval,exitflag]=optimizer_function_wrapper(objective_function_handle,start_par_value,varargin)
% Demonstrates how to invoke external optimizer for mode_computation

%set options of optimizer
dum = 1;
if dum == 1
% paralelizar
% parpool
tic
% call optimizer
% [opt_par_values,fval,exitflag,output,grad,hessian_mat] = fminunc(objective_function_handle,start_par_value,varargin);
[opt_par_values,fval,exitflag] = fminunc(objective_function_handle,start_par_value,varargin{:});
end
toc
% p = gcp 
% delete(gcp)


end

You are missing the options-structure for fminsearch. Use

optim_options = optimset('display','iter','MaxFunEvals',1000000,'MaxIter',6000,'TolFun',1e-8,'TolX',1e-6);
[opt_par_values,fval,exitflag] = fminsearch(objective_function_handle,start_par_value,optim_options,varargin{:});

Thanks a lot dear jpfeifer.