47.2. Creation Routine

The TAO solver is initialized to for a particular algorithm in a separate routine. This routine sets default convergence tolerances, creates a line search or linear solver if needed, and creates structures needed by this solver. For example, the routine that creates the nonlinear conjugate gradient algorithm shown above can be implemented as follows.
EXTERN_C_BEGIN 
int TaoCreate_CG_FR(TAO_SOLVER tao) 
{ 
  TAO_CG *cg; 
  int    info; 
 
  TaoFunctionBegin; 
 
  info = TaoNew(TAO_CG,&cg); CHKERRQ(info); 
 
  info = TaoSetMaximumIterates(tao,2000); CHKERRQ(info); 
  info = TaoSetTolerances(tao,1e-4,1e-4,0,0); CHKERRQ(info); 
  info = TaoSetMaximumFunctionEvaluations(tao,4000); CHKERRQ(info); 
 
  info = TaoCreateMoreThuenteLineSearch(tao,0,0.1); CHKERRQ(info); 
 
  info = TaoSetTaoSolveRoutine(tao,TaoSolve_CG_FR,(void*)cg); CHKERRQ(info); 
  info = TaoSetTaoSetUpDownRoutines(tao,TaoSetUp_CG,TaoDestroy_CG); CHKERRQ(info); 
  info = TaoSetTaoOptionsRoutine(tao,TaoSetOptions_CG_FR); CHKERRQ(info); 
  info = TaoSetTaoViewRoutine(tao,TaoView_CG); CHKERRQ(info); 
 
  TaoFunctionReturn(0); 
} 
EXTERN_C_END 
The first thing this routine does after declaring some variables, is allocate memory for the TAO_CG data structure. Clones of the the variable vector assed into TAO in the TaoCreate() routine are used as the two work vectors. This routine also sets some default convergence tolerances and creates a particular line search. These defaults could be specified in the routine that solves the problem, but specifying them here gives the user the opportunity to modify these parameters.

Finally, this solvers passes to TAO the names of all the other routines used by the solver.

Note that the lines EXTERN_C_BEGIN and EXTERN_C_END surround this routine. These macros are required to preserve the name of this function without any name-mangling from the C++ compiler.