Commit 0d4e4974 authored by David Bommes's avatar David Bommes
Browse files

changed

-Finders to support Fedora
-fixed some configuration issues (not installed libraries...)

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@129 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 686cfe9a
......@@ -16,6 +16,9 @@ if( QT4_FOUND)
add_definitions (-DQT4_FOUND)
# message( WARNING " USING QT4" )
endif ()
set (COMISO_QT4_CONFIG_FILE_SETTINGS "#define COMISO_QT4_AVAILABLE 1" )
else()
set (COMISO_QT4_CONFIG_FILE_SETTINGS "#define COMISO_QT4_AVAILABLE 0" )
endif ()
acg_get_version ()
......@@ -68,6 +71,13 @@ else ()
message (STATUS "SUITESPARSE not found!")
set (COMISO_SUITESPARSE_CONFIG_FILE_SETTINGS "#define COMISO_SUITESPARSE_AVAILABLE 0" )
endif ()
# special handling, since spqr is incorrect in several distributions
if(SUITESPARSE_SPQR_VALID)
set (COMISO_SUITESPARSE_SPQR_CONFIG_FILE_SETTINGS "#define COMISO_SUITESPARSE_SPQR_AVAILABLE 1" )
else()
message (STATUS "SUITESPARSE SPQR seems to be invalid!")
set (COMISO_SUITESPARSE_SPQR_CONFIG_FILE_SETTINGS "#define COMISO_SUITESPARSE_SPQR_AVAILABLE 0" )
endif()
find_package (MPI)
if (MPI_FOUND )
......@@ -102,6 +112,18 @@ else ()
set (COMISO_TAO_CONFIG_FILE_SETTINGS "#define COMISO_TAO_AVAILABLE 0" )
endif ()
find_package (METIS)
if (METIS_FOUND )
set (COMISO_METIS_CONFIG_FILE_SETTINGS "#define COMISO_METIS_AVAILABLE 1" )
list( APPEND COMISO_INCLUDE_DIRECTORIES ${METIS_INCLUDE_DIRS} )
list( APPEND COMISO_LINK_DIRECTORIES ${METIS_LIBRARY_DIRS} )
list( APPEND COMISO_LINK_LIBRARIES ${METIS_LIBRARIES} )
else()
set (COMISO_METIS_CONFIG_FILE_SETTINGS "#define COMISO_METIS_AVAILABLE 0" )
message (STATUS "METIS not found!")
endif ()
find_package (MUMPS)
if (MUMPS_FOUND )
set (COMISO_MUMPS_CONFIG_FILE_SETTINGS "#define COMISO_MUMPS_AVAILABLE 1" )
......@@ -173,6 +195,18 @@ else ()
set (COMISO_ARPACK_CONFIG_FILE_SETTINGS "#define COMISO_ARPACK_AVAILABLE 0" )
endif ()
find_package (CPLEX)
if (CPLEX_FOUND )
set (COMISO_CPLEX_CONFIG_FILE_SETTINGS "#define COMISO_CPLEX_AVAILABLE 1" )
list( APPEND COMISO_INCLUDE_DIRECTORIES ${CPLEX_INCLUDE_DIRS} )
# list( APPEND COMISO_LINK_DIRECTORIES ${CPLEX_LIBRARY_DIR} )
# list( APPEND COMISO_LINK_DIRECTORIES ${CPLEX_CONCERT_LIBRARY_DIR} )
list( APPEND COMISO_LINK_LIBRARIES ${CPLEX_LIBRARIES} )
else ()
message (STATUS "CPLEX not found!")
set (COMISO_ARPACK_CONFIG_FILE_SETTINGS "#define COMISO_CPLEX_AVAILABLE 0" )
endif ()
include_directories (
..
${CMAKE_CURRENT_SOURCE_DIR}
......@@ -289,6 +323,9 @@ endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/eigen_solver/CMakeLists.txt" )
add_subdirectory (Examples/eigen_solver)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_nsolver/CMakeLists.txt" )
add_subdirectory (Examples/small_nsolver)
endif()
// Build time dependencies for CoMiso
@COMISO_QT4_CONFIG_FILE_SETTINGS@
@COMISO_BLAS_CONFIG_FILE_SETTINGS@
@COMISO_GMM_CONFIG_FILE_SETTINGS@
@COMISO_SUITESPARSE_CONFIG_FILE_SETTINGS@
@COMISO_SUITESPARSE_SPQR_CONFIG_FILE_SETTINGS@
@COMISO_MPI_CONFIG_FILE_SETTINGS@
@COMISO_HSL_CONFIG_FILE_SETTINGS@
@COMISO_PETSC_CONFIG_FILE_SETTINGS@
@COMISO_TAO_CONFIG_FILE_SETTINGS@
@COMISO_IPOPT_CONFIG_FILE_SETTINGS@
@COMISO_MUMPS_CONFIG_FILE_SETTINGS@
@COMISO_METIS_CONFIG_FILE_SETTINGS@
@COMISO_TAUCS_CONFIG_FILE_SETTINGS@
@COMISO_GUROBI_CONFIG_FILE_SETTINGS@
@COMISO_ARPACK_CONFIG_FILE_SETTINGS@
@COMISO_CPLEX_CONFIG_FILE_SETTINGS@
......@@ -9,6 +9,7 @@
//== INCLUDES =================================================================
#include "LinearConstraintHandlerElimination.hh"
#include <CoMISo/Solver/SparseQRSolver.hh>
//== NAMESPACES ===============================================================
......@@ -29,6 +30,9 @@ initialize( const MatrixT& _C, const VectorT& _c)
}
else
{
// require SPQR SOLVER!!!
#if(COMISO_SUITESPARSE_SPQR_AVAILABLE)
// Construct constraints basis form via QR-factorization (see Nocedal 426...)
// Constraints in basis transformation form x_orig = b_ + C_*x_reduced
// notice that C_ is a basis of the nullspace of the constraints
......@@ -93,6 +97,9 @@ initialize( const MatrixT& _C, const VectorT& _c)
// std::cerr << "rank: " << rank << std::endl;
// std::cerr << "dim Q = " << gmm::mat_nrows(Q) << " x " << gmm::mat_ncols(Q) << std::endl;
// std::cerr << "dim R = " << gmm::mat_nrows(R) << " x " << gmm::mat_ncols(R) << std::endl;
#else
std::cerr << "ERROR: SQPR-Solver required by LinearConstraintHandlerElimination not available !!!" << std::endl;
#endif
}
}
......
......@@ -141,6 +141,117 @@ solve( NProblemGmmInterface* _base)
//-----------------------------------------------------------------------------
int
TAOSolver::
solve( NProblemInterface* _base)
{
// // initialize (only once)
// initialize();
// std::cerr << "tao 1\n";
// // MPI_Init(0,0);
// char *libm="libmpi.so";
// dlopen(libm,RTLD_GLOBAL);
if(!initialized_)
{
/* Initialize TAO,PETSc */
// non command line arguments necessary ...
std::cerr << "Initialize MPI/Petsc/TAO ";
static char help[] ="help\n";
int argc = 0;
char **argv;
// MPI_Init(&argc, &argv);
PetscInitialize( &argc, &argv,(char *)0,help );
TaoInitialize ( &argc, &argv,(char *)0,help );
initialized_ = true;
std::cerr << " done!!!\n";
}
/* used to check for functions returning nonzeros */
int info;
// check for single processor
int size;
MPI_Comm_size(MPI_COMM_WORLD,&size);
if (size >1) {
PetscPrintf(PETSC_COMM_SELF,"TAOSolver is intended for single processor use!\n");
SETERRQ(1,"Incorrect number of processors");
}
/* Create TAO solver and set desired solution method */
// TaoMethod method="tao_cg"; /* minimization method */
TaoMethod method="tao_ntr"; /* minimization method */
// TaoMethod method="tao_nm"; /* minimization method */
TAO_SOLVER tao; /* TAO_SOLVER solver context */
TAO_APPLICATION testapp; /* The PETSc application */
info = TaoCreate(PETSC_COMM_SELF,method,&tao); CHKERRQ(info);
info = TaoApplicationCreate(PETSC_COMM_SELF,&testapp); CHKERRQ(info);
// initalize vector
int n = _base->n_unknowns();
Vec x;
info = VecCreateSeq(PETSC_COMM_SELF, n, &x); CHKERRQ(info);
PetscScalar* X;
info = VecGetArray(x,&X); CHKERRQ(info);
_base->initial_x(X);
info = VecRestoreArray(x,&X); CHKERRQ(info);
// initialize matrix
/* Create a matrix data structure to store the Hessian. This structure will be used by TAO */
Mat H;
// ToDo: get nonzero_pattern
// int nnz[1]; nnz[0] = 1;
// info = MatCreateSeqAIJ(PETSC_COMM_SELF,n,n,0,nnz,&H); /* PETSc routine */
info = MatCreateSeqAIJ(PETSC_COMM_SELF,n,n,0,0,&H); /* PETSc routine */
info = MatSetOption(H,MAT_SYMMETRIC,PETSC_TRUE); CHKERRQ(info); /* PETSc flag */
info = TaoAppSetHessianMat(testapp,H,H); CHKERRQ(info); /* A TAO routine */
// initialize solution vector
info = TaoAppSetInitialSolutionVec(testapp,x); CHKERRQ(info);
/* Provide TAO routines for function evaluation */
info = TaoAppSetObjectiveRoutine(testapp, objective2, (void*) _base); CHKERRQ(info);
info = TaoAppSetGradientRoutine (testapp, gradient2 , (void*) _base); CHKERRQ(info);
info = TaoAppSetHessianRoutine (testapp, hessian2 , (void*) _base); CHKERRQ(info);
/* SOLVE THE APPLICATION */
info = TaoSolveApplication(testapp,tao); CHKERRQ(info);
/* Get information on termination */
TaoTerminateReason reason;
info = TaoGetTerminationReason(tao,&reason); CHKERRQ(info);
if (reason <= 0)
std::cerr << "Warning: TAO-Solver did not converge!!!\n";
else
std::cerr << "TAO-Solver converged!!!\n";
// To View TAO solver information use
info = TaoView(tao); CHKERRQ(info);
// if successfull get and store result
// if( reason)
{
info = TaoAppGetSolutionVec(testapp, &x);
info = VecGetArray(x,&X); CHKERRQ(info);
_base->store_result( X);
info = VecRestoreArray(x,&X); CHKERRQ(info);
}
// VecView(x, PETSC_VIEWER_STDOUT_WORLD);
// /* Free TAO data structures */
info = TaoDestroy(tao); CHKERRQ(info);
info = TaoAppDestroy(testapp); CHKERRQ(info);
return reason;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
objective( TAO_APPLICATION _app, Vec _x, double* _result, void* _base)
......@@ -248,6 +359,107 @@ hessian(TAO_APPLICATION _app, Vec _x, Mat* _H, Mat* _H_pre, MatStructure* _H_str
//-----------------------------------------------------------------------------
int
TAOSolver::
objective2( TAO_APPLICATION _app, Vec _x, double* _result, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x;
/* Get pointers to vector data */
int info = VecGetArray(_x,&x); CHKERRQ(info);
// evaluate function
(*_result) = base->eval_f(x);
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
gradient2(TAO_APPLICATION _app, Vec _x, Vec _g, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x, *g;
int info;
/* Get pointers to vector data */
info = VecGetArray(_x,&x); CHKERRQ(info);
info = VecGetArray(_g,&g); CHKERRQ(info);
// compute gradient
base->eval_gradient( x, g);
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
info = VecRestoreArray(_g,&g); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
hessian2(TAO_APPLICATION _app, Vec _x, Mat* _H, Mat* _H_pre, MatStructure* _H_struct, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x;
/* Get pointers to vector data */
int info = VecGetArray(_x,&x); CHKERRQ(info);
/* Initialize matrix entries to zero */
info = MatZeroEntries(*_H); CHKERRQ(info);
// iterate over non-zero elements
NProblemInterface::SMatrixNP H;
base->eval_hessian( x, H);
for(int i=0; i<H.outerSize(); ++i)
{
int m = 1;
int n = 1;
int idxm[1]; idxm[0] = i;
int idxn[1];
PetscScalar values[1];
for (NProblemInterface::SMatrixNP::InnerIterator it(H,i); it; ++it)
{
idxm[0] = it.row();
idxn[0] = it.col();
values[0] = it.value();
info = MatSetValues(*_H, m, idxm, n, idxn, values, INSERT_VALUES);
}
}
/* Assemble the matrix */
info = MatAssemblyBegin(*_H,MAT_FINAL_ASSEMBLY); CHKERRQ(info);
info = MatAssemblyEnd(*_H,MAT_FINAL_ASSEMBLY); CHKERRQ(info);
*_H_struct = SAME_NONZERO_PATTERN;
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
void
TAOSolver::
initialize()
......@@ -411,6 +623,128 @@ solve( NProblemGmmInterface* _base)
//-----------------------------------------------------------------------------
int
TAOSolver::
solve( NProblemInterface* _base)
{
// // initialize (only once)
// initialize();
// std::cerr << "tao 1\n";
// // MPI_Init(0,0);
// char *libm="libmpi.so";
// dlopen(libm,RTLD_GLOBAL);
if(!initialized_)
{
/* Initialize TAO,PETSc */
// non command line arguments necessary ...
std::cerr << "Initialize MPI/Petsc/TAO ";
static char help[] ="help\n";
int argc = 0;
char **argv;
// MPI_Init(&argc, &argv);
PetscInitialize( &argc, &argv,(char *)0,help );
TaoInitialize ( &argc, &argv,(char *)0,help );
initialized_ = true;
std::cerr << " done!!!\n";
}
/* used to check for functions returning nonzeros */
int info;
// check for single processor
int size;
MPI_Comm_size(MPI_COMM_WORLD,&size);
if (size >1) {
PetscPrintf(PETSC_COMM_SELF,"TAOSolver is intended for single processor use!\n");
SETERRQ(PETSC_COMM_SELF,1,"Incorrect number of processors");
}
/* Create TAO solver with desired solution method */
TaoSolver tao; /* TaoSolver solver context */
TaoCreate(PETSC_COMM_SELF,&tao);
TaoSetType(tao,"tao_ntr");
/* Create TAO solver and set desired solution method */
// TaoMethod method="tao_cg"; /* minimization method */
// TaoMethod method="tao_ntr"; /* minimization method */
// TaoMethod method="tao_nm"; /* minimization method */
// TAO_SOLVER tao; /* TAO_SOLVER solver context */
// TAO_APPLICATION testapp; /* The PETSc application */
// info = TaoCreate(PETSC_COMM_SELF,method,&tao); CHKERRQ(info);
// info = TaoApplicationCreate(PETSC_COMM_SELF,&testapp); CHKERRQ(info);
// initalize vector
int n = _base->n_unknowns();
Vec x;
info = VecCreateSeq(PETSC_COMM_SELF, n, &x); CHKERRQ(info);
PetscScalar* X;
info = VecGetArray(x,&X); CHKERRQ(info);
_base->initial_x(X);
info = VecRestoreArray(x,&X); CHKERRQ(info);
// initialize matrix
/* Create a matrix data structure to store the Hessian. This structure will be used by TAO */
Mat H;
// ToDo: get nonzero_pattern
// int nnz[1]; nnz[0] = 1;
// info = MatCreateSeqAIJ(PETSC_COMM_SELF,n,n,0,nnz,&H); /* PETSc routine */
info = MatCreateSeqAIJ(PETSC_COMM_SELF,n,n,0,0,&H); /* PETSc routine */
info = MatSetOption(H,MAT_SYMMETRIC,PETSC_TRUE); CHKERRQ(info); /* PETSc flag */
//info = TaoAppSetHessianMat(testapp,H,H); CHKERRQ(info); /* A TAO routine */
// initialize solution vector
// info = TaoAppSetInitialSolutionVec(testapp,x); CHKERRQ(info);
TaoSetInitialVector(tao,x);
/* Provide TAO routines for function evaluation */
TaoSetObjectiveRoutine(tao, objective2, (void*) _base);
TaoSetGradientRoutine (tao, gradient2 , (void*) _base);
TaoSetHessianRoutine (tao, H, H, hessian2 , (void*) _base);
/* SOLVE */
TaoSolve(tao);
/* Get information on termination */
TaoSolverTerminationReason reason;
TaoGetTerminationReason(tao,&reason);
if (reason <= 0)
std::cerr << "Warning: TAO-Solver did not converge!!!\n";
else
std::cerr << "TAO-Solver converged!!!\n";
// To View TAO solver information use
info = TaoView(tao, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(info);
// if successfull get and store result
// if( reason)
{
TaoGetSolutionVector(tao, &x);
info = VecGetArray(x,&X); CHKERRQ(info);
_base->store_result( X);
info = VecRestoreArray(x,&X); CHKERRQ(info);
}
// VecView(x, PETSC_VIEWER_STDOUT_WORLD);
// /* Free TAO data structures */
TaoDestroy(&tao);
/* Free PETSc data structures */
VecDestroy(&x);
MatDestroy(&H);
TaoFinalize();
return reason;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
objective( TaoSolver _tao, Vec _x, double* _result, void* _base)
......@@ -518,6 +852,108 @@ hessian(TaoSolver _tao, Vec _x, Mat* _H, Mat* _H_pre, MatStructure* _H_struct, v
//-----------------------------------------------------------------------------
int
TAOSolver::
objective2( TaoSolver _tao, Vec _x, double* _result, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x;
/* Get pointers to vector data */
int info = VecGetArray(_x,&x); CHKERRQ(info);
// evaluate function
(*_result) = base->eval_f(x);
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
gradient2(TaoSolver _tao, Vec _x, Vec _g, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x, *g;
int info;
/* Get pointers to vector data */
info = VecGetArray(_x,&x); CHKERRQ(info);
info = VecGetArray(_g,&g); CHKERRQ(info);
// compute gradient
base->eval_gradient( x, g);
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
info = VecRestoreArray(_g,&g); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
int
TAOSolver::
hessian2(TaoSolver _tao, Vec _x, Mat* _H, Mat* _H_pre, MatStructure* _H_struct, void* _base)
{
NProblemInterface* base = (NProblemInterface*) _base;
PetscScalar *x;
/* Get pointers to vector data */
int info = VecGetArray(_x,&x); CHKERRQ(info);
/* Initialize matrix entries to zero */
info = MatZeroEntries(*_H); CHKERRQ(info);
// iterate over non-zero elements
NProblemInterface::SMatrixNP H;
base->eval_hessian( x, H);
for(int i=0; i<H.outerSize(); ++i)
{
int m = 1;
int n = 1;
int idxm[1]; idxm[0] = i;
int idxn[1];
PetscScalar values[1];
for (NProblemInterface::SMatrixNP::InnerIterator it(H,i); it; ++it)
{
idxm[0] = it.row();
idxn[0] = it.col();
values[0] = it.value();
info = MatSetValues(*_H, m, idxm, n, idxn, values, INSERT_VALUES);
}
}
/* Assemble the matrix */
info = MatAssemblyBegin(*_H,MAT_FINAL_ASSEMBLY); CHKERRQ(info);
info = MatAssemblyEnd(*_H,MAT_FINAL_ASSEMBLY); CHKERRQ(info);
*_H_struct = SAME_NONZERO_PATTERN;
/* Restore vectors */
info = VecRestoreArray(_x,&x); CHKERRQ(info);
return 0;
}
//-----------------------------------------------------------------------------
void
TAOSolver::
initialize()
......
......@@ -20,6 +20,7 @@
#include <gmm/gmm.h>
#include "NProblemGmmInterface.hh"
#include "NProblemInterface.hh"
//== FORWARDDECLARATIONS ======================================================
......@@ -43,11 +44,13 @@ public:
/// Default constructor
TAOSolver() {}
/// Destructor
~TAOSolver() {}
// solve problem
static int solve( NProblemInterface* _base);
static int solve( NProblemGmmInterface* _base);
......@@ -63,10 +66,18 @@ private:
static int objective(TAO_APPLICATION,Vec,double*,void*);
static int gradient (TAO_APPLICATION,Vec,Vec ,void*);
static int hessian (TAO_APPLICATION,Vec,Mat*,Mat*,MatStructure*,void*);
static int objective2(TAO_APPLICATION,Vec,double*,void*);
static int gradient2 (TAO_APPLICATION,Vec,Vec ,void*);
static int hessian2 (TAO_APPLICATION,Vec,Mat*,Mat*,MatStructure*,void*);
#else
static PetscErrorCode objective(TaoSolver,Vec,double*,void*);
static PetscErrorCode gradient (TaoSolver,Vec,Vec ,void*);
static PetscErrorCode hessian (TaoSolver,Vec,Mat*,Mat*,MatStructure*,void*);
static PetscErrorCode objective2(TaoSolver,Vec,double*,void*);
static PetscErrorCode gradient2 (TaoSolver,Vec,Vec ,void*);
static PetscErrorCode hessian2 (TaoSolver,Vec,Mat*,Mat*,MatStructure*,