Permalink
Browse files

almost have simple example working

  • Loading branch information...
1 parent 7e3cbd6 commit 9e4c426e960154f375a45cbe2578345b0cb2a9b3 @sarich sarich committed Jul 23, 2008
View
@@ -46,7 +46,7 @@ F_SH_LIB_PATH = ${FC_LINKER_SLFLAG}${TAO_LIB_DIR} ${TAO_F_SH_LIB_PATH}
# is important!
#
# ??TAO_BLIB = -L${TAO_LIB_DIR} -ltao ${PETSC_SYS_LIB}
-TAO_LIB = -L${TAO_LIB_DIR} -ltaolinesearch -ltao
+TAO_LIB = -L${TAO_LIB_DIR} -ltaosolver -ltaolinesearch -ltao
#
# Link if you are using the TAO Fortran interface.
@@ -3,15 +3,17 @@
#include "taosolver.h"
#include "taolinesearch.h"
+#include "petscksp.h"
typedef struct _TaoSolverOps *TaoSolverOps;
struct _TaoSolverOps {
PetscErrorCode (*computeobjective)(TaoSolver, Vec, PetscScalar*, void*);
PetscErrorCode (*computeobjectiveandgradient)(TaoSolver, Vec, PetscScalar*, Vec, void*);
PetscErrorCode (*computegradient)(TaoSolver, Vec, Vec, void*);
- PetscErrorCode (*converged)(TaoSolver,void*);
- PetscErrorCode (*convergeddestroy)(void*);
+ PetscErrorCode (*convergencetest)(TaoSolver,void*);
+ PetscErrorCode (*convergencedestroy)(void*);
+
PetscErrorCode (*setup)(TaoSolver);
PetscErrorCode (*solve)(TaoSolver);
PetscErrorCode (*view)(TaoSolver, PetscViewer);
@@ -23,8 +25,11 @@ struct _TaoSolverOps {
struct _p_TaoSolver {
PETSCHEADER(struct _TaoSolverOps);
- void *user_obj;
- void *user_grad;
+ void *user_objP;
+ void *user_objgradP;
+ void *user_gradP;
+ void *user_hessP;
+ void *user_jacP;
PetscErrorCode (*monitor[MAXTAOMONITORS])(TaoSolver,void*);
PetscErrorCode (*monitordestroy[MAXTAOMONITORS])(void*);
@@ -37,33 +42,63 @@ struct _p_TaoSolver {
void *data;
Vec solution;
+ Vec gradient;
+ Vec stepdirection;
+ PetscReal step;
+ PetscReal residual;
+ PetscReal gnorm0;
+ PetscReal cnorm;
+ PetscReal cnorm0;
+ PetscReal fc;
+
+
PetscInt max_its;
PetscInt max_funcs;
+ PetscInt max_constraints;
PetscInt nfuncs;
PetscInt ngrads;
PetscInt nfuncgrads;
PetscInt nhess;
- PetscInt iter;
+ PetscInt niter;
+ PetscInt nconstraints;
+ PetscInt njac;
+
- TaoLineSearch *ls;
+ TaoLineSearch linesearch;
+ PetscTruth lsflag; /* goes up when line search fails */
+ KSP *ksp;
- PetscScalar residual;
- PetscScalar rtol;
+ PetscReal fatol;
+ PetscReal frtol;
+ PetscReal gatol;
+ PetscReal grtol;
+ PetscReal gttol;
+ PetscReal catol;
+ PetscReal crtol;
+ PetscReal xtol;
+ PetscReal trtol;
+ PetscReal fmin;
PetscTruth printreason;
+ PetscTruth viewtao;
+ PetscTruth viewgradient;
+ PetscTruth viewconstraint;
+ PetscTruth viewhessian;
+ PetscTruth viewjacobian;
- PetscReal *conv_hist; /* Number of iteration histories to keep */
+ PetscInt conv_hist_max;/* Number of iteration histories to keep */
+ PetscReal *conv_hist;
PetscInt *conv_hist_feval; /* Number of func evals at each iteration */
+ PetscInt *conv_hist_fgeval; /* Number of func/grad evals at each iteration */
PetscInt *conv_hist_geval; /* Number of grad evals at each iteration */
PetscInt *conv_hist_heval; /* Number of hess evals at each iteration */
PetscInt conv_hist_len;
- PetscInt conv_hist_max;
PetscTruth conv_hist_reset;
};
-extern PetscLogEvent TaoSolver_Solve, TaoSolver_ObjectiveEval, TaoSolver_GradientEval, TaoSolver_HessianEval, TaoSolver_JacobianEval;
+extern PetscLogEvent TaoSolver_Solve, TaoSolver_ObjectiveEval, TaoSolver_ObjGradientEval, TaoSolver_GradientEval, TaoSolver_HessianEval, TaoSolver_JacobianEval;
View
@@ -1,6 +1,11 @@
#if !defined(__TAO_SYS_H)
#define __TAO_SYS_H
+#define TaoMid(a,b,c) (((a) < (b)) ? \
+ (((b) < (c)) ? (b) : \
+ (((a) < (c)) ? (c) : (a))) : \
+ (((a) < (c)) ? (a) : \
+ (((b) < (c)) ? (c) : (b))))
#if defined(_MSC_VER)
@@ -9,7 +14,7 @@
#define TaoInf(a) (!_finite(a))
#define TaoInfOrNaN(a) TaoInf(a)
-#else
+#elif defined(PETSC_HAVE_ISNAN)
// These tests are from ISO C99
#define TaoNaN(a) isnan(a)
@@ -19,10 +24,10 @@
#endif
#define TAO_DEFAULT -13456834
-#define TAO_INFINITY 1.0e20
-#define TAO_NINFINITY -1.0e20
+#define TAO_INFINITY 1.0e100
+#define TAO_NINFINITY -1.0e100
#define TAO_NULL 0
-#define TAO_EPSILON DBL_EPSILON
+#define TAO_EPSILON PETSC_MACHINE_EPSILON
/*
PetscErrorCode PETSC_DLLEXPORT TaoInitialize(int*,char ***,char[],const char[]);
View
@@ -7,7 +7,7 @@ PETSC_EXTERN_CXX_BEGIN
typedef struct _p_TaoSolver* TaoSolver;
#define TaoSolverType const char*
-extern PetscCookie PETSC_DLLEXPORT TAOSOLVER_COOKIE;
+extern PetscCookie TAOSOLVER_DLLEXPORT TAOSOLVER_COOKIE;
/* Convergence flags.
Be sure to check that these match the flags in
@@ -27,38 +27,48 @@ typedef enum {/* converged */
TAO_DIVERGED_TR_REDUCTION = -7,
TAO_DIVERGED_USER = -8, /* User defined */
/* keep going */
- TAO_CONTINUE_ITERATING = 0} TaoSolverTerminateReason;
+ TAO_CONTINUE_ITERATING = 0} TaoSolverConvergedReason;
-#if defined PETSC_USE_DYNAMIC_LIBRARIES)
+extern const char **TaoSolverConvergedReasons;
+
+#if defined PETSC_USE_DYNAMIC_LIBRARIES
#define TaoSolverRegisterDynamic(a,b,c,d) TaoSolverRegister(a,b,c,0)
#else
#define TaoSolverRegisterDynamic(a,b,c,d) TaoSolverRegister(a,b,c,d)
#endif
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverCreate(MPI_Comm,TaoSolver*);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetFromOptions(TaoSolver);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetUp(TaoSolver);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetType(TaoSolver, TaoSolverType);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverDestroy(TaoSolver);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetOptionsPrefix(TaoSolver,const char []);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverView(TaoSolver, PetscViewer);
-
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSolve(TaoSolver);
-/* EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverRegister(const char [], const char[], const char[],
- PetscErrorCode (*)(TaoSolver)); */
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverGetConvergedReason(TaoSolver,TaoSolverTerminateReason*);
-
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetInitialVector(TaoSolver, Vec);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetObjective(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, PetscReal*,void*), void*);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetGradient(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, Vec, void*), void*);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetObjectiveGradient(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, PetscReal*, Vec, void*), void*);
-
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverComputeObjective(TaoSolver, Vec, PetscReal*);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverComputeGradient(TaoSolver, Vec, Vec);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverComputeObjectiveGradient(TaoSolver, Vec, PetscReal*, Vec);
-
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverGetTolerances(TaoSolver, PetscReal*, PetscReal*, PetscReal*, PetscReal*, PetscReal*);
-EXTERN PetscErrorCode PETSC_DLLEXPORT TaoSolverSetTolerances(TaoSolver, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverCreate(MPI_Comm,TaoSolver*);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetFromOptions(TaoSolver);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetUp(TaoSolver);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetType(TaoSolver, TaoSolverType);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverDestroy(TaoSolver);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetOptionsPrefix(TaoSolver,const char []);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverView(TaoSolver, PetscViewer);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSolve(TaoSolver);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverRegister(const char [], const char[], const char[], PetscErrorCode (*)(TaoSolver));
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverRegisterAll(const char[]);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverRegisterDestroy(void);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverGetConvergedReason(TaoSolver,TaoSolverConvergedReason*);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetInitialVector(TaoSolver, Vec);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetObjective(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, PetscReal*,void*), void*);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetGradient(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, Vec, void*), void*);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetObjectiveGradient(TaoSolver, PetscErrorCode(*)(TaoSolver, Vec, PetscReal*, Vec, void*), void*);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverComputeObjective(TaoSolver, Vec, PetscReal*);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverComputeGradient(TaoSolver, Vec, Vec);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverComputeObjectiveGradient(TaoSolver, Vec, PetscReal*, Vec);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverGetTolerances(TaoSolver, PetscReal*, PetscReal*, PetscReal*, PetscReal*, PetscReal*);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetTolerances(TaoSolver, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverResetStatistics(TaoSolver);
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverSetDefaultMonitors(TaoSolver);
+
+EXTERN PetscErrorCode TAOSOLVER_DLLEXPORT TaoSolverDefaultConvergenceTest(TaoSolver,void*);
View
@@ -117,6 +117,9 @@ tao_deletelibs:
tao_shared:
-@echo "tao_shared not implemented yet..."
+tao_alletags:
+ -@maint/generateetags.py
+
tao_testexamples_c:
-@${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} TAO_DIR=${TAO_DIR} ACTION=testexamples_C tree
View
@@ -2,10 +2,10 @@ ALL: lib
CFLAGS =
FFLAGS =
-SOURCEC = taosolver.c taosolverfg.c taosolverregi.c taosolverhj.c dlregibstaosolver.c
+SOURCEC = taosolver.c taosolver_fg.c taosolverregi.c taosolver_hj.c dlregistaosolver.c
SOURCEF =
SOURCEH =
-OBJSC = taosolver.o taosolverfg.o taosolverregi.o taosolverhj.o dlregistaosolver.o
+OBJSC = taosolver.o taosolver_fg.o taosolverregi.o taosolver_hj.o dlregistaosolver.o
OBJSF =
LIBBASE = libtaosolver
MANSEC = TAO_SOLVER
Oops, something went wrong.

0 comments on commit 9e4c426

Please sign in to comment.