
http://www.mcs.anl.gov/tao/exercises11.txt




****************************************************
TAO - Toolkit for Advanced Optimization
        
Tutorial and Exercises

Workshop on the ACTS Toolkit

August 16-19, 2011

National Energy Research Scientific Computing Center
****************************************************

Locate the TAO and PETSc documentation at 
 * http://www.mcs.anl.gov/tao
 * http://www.mcs.anl.gov/petsc

Set the environmental variables TAO_DIR, PETSC_DIR, and PETSC_ARCH
e.g., for bash shells:
  > export PETSC_DIR=/home/sarich/petsc-3.1
  > export PETSC_ARCH=linux-gnu-cxx-debug
  > export TAO_DIR=/home/sarich/tao-1.10.1

for tcsh shells:
  > setenv PETSC_DIR /home/sarich/petsc-3.1
  > setenv PETSC_ARCH linux-gnu-cxx-debug
  > setenv TAO_DIR /home/sarich/tao-1.10.1

For Carver:
  > module load tao/1.10.1_g
  > source /usr/common/acts/acts-tuts
  > runnow



Create a subdirectory such as taoexamples, enter it, and copy several example problems to the new directory using the commands:
  > mkdir taoexamples
  > cd taoexamples
  > cp -R $TAO_DIR/src/unconstrained/examples/tutorials/* .
  > ls

There should be a makefile and several examples ending in .c and .F
   eptorsion1.c eptorsion2.c eptorsion2f.F minsurf1.c minsurf2.c rosenbrock1.c
   rosenbrock1f.F makefile (and a few other files)


************************
Run an example with TAO.
************************

We are going to use TAO to minimize the function 
    f(x1,x2) = 99*(x1-(x1)^2)^2 + (1-x1)^2 

on a single processor.

Compile the program using
  > make rosenbrock1
  (or make rosenbrock1f for Fortran users)


On your laptop, execute the program with 
  > ./rosenbrock1 -tao_monitor -tao_view 
  (or ./rosenbrock1f -tao_monitor -tao_view)
On Carver (after using runnow):
  > mpiexec -n 1 ./rosenbrock1 -tao_monitor -tao_view

  What method was used to solve the problem?
  What is the function value at the final iterate? 
  How many iterates were used to reach the solution?  
  How many function evaluations?



***********************************************************


Another TAO example finds the minimum surface area of an object over a
two-dimensional domain in accordance with some boundary conditions.

Compile and execute the minsurf2 example using
    
  > make minsurf2
  > mpiexec -n 2 ./minsurf2 -tao_monitor -tao_view


This problem uses the variables 'mx' and 'my' to determine
the discretization of the grid.  By default, these values are set to
4 (4 * 4 = 16 variables). Increase the discretization of the 
domain by using the command 

  > mpiexec -n 2 ./minsurf2 -tao_monitor -tao_view -mx 20 -my 20

How does this affect the solve?  more time? more iterations?
Try different solvers using the option -tao_method followed by
'tao_cg', 'tao_lmvm', 'tao_ntr', 'tao_nls', or 'tao_nm'.
   cg   = conjugate gradient 
   lmvm = limited memory variable metric quasi-newton method
   ntr  = newton trust region
   nls  = newton line search
   nm   = nelder-mead derivative-free


How many iterations do the different solvers require to solve the problem?


Now how many iterations does each solver take?

Execute the programs from the last step again, but this time use the command line option -log_summary to get detailed performance information.

Look under the PETSc Performance Summary section and determine how long
each algorithm takes to solve the problem. How many floating point operations (flops) are required? 



Run the problem minsurf2.c on four processors and view the output.

  > mpiexec -n 4 ./minsurf2 -tao_monitor -mx 20 -my 20 -log_summary


Locate minsurf2.c in the TAO documentation on its web site.  Browse through
 the online version this example and follow the links for
TaoCreate() and other routines.  Read the online documentation for these
 routines to learn more about their usage and arguments.

Run minsurf2 again using other unconstrained minimization 
methods.    You can change the solver by modifying the arguments of 
TaoCreate() or using the runtime option -tao_method <solver>.
 
  What is the function value at the final iterate?
  How many iterates were used to reach
  the solution?  What was the final residual value? What does the residual represent?


  Change the starting vector x by editing the file minsurf2.c.  
  Use the PETSc method VecSet()
  to set the vector components to a constant, or VecSetValue() to set 
  an individual element (remember to follow any VecSetValue() calls
  with VecAssemblyBegin() and VecAssemblyEnd()).  Compile the program again and run it.
  How did the starting point affect the convergence?


You can print the solution after the solve is complete using the PETSc command
VecView().






