Skip to content

Commit

Permalink
allows to compile umfpack in 3rdParty and use it in cpp-runtime
Browse files Browse the repository at this point in the history
only the LGPL version in 3rdParty is used



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22028 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Michael Kloeppel committed Aug 27, 2014
1 parent 40d25e0 commit 02d1168
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 128 deletions.
20 changes: 18 additions & 2 deletions Makefile.common
Expand Up @@ -62,7 +62,7 @@ install-python:
install-openturns: mkbuilddirs
(time cp SimulationRuntime/OpenTurns/* $(builddir_share)/omc/scripts/OpenTurns/)

interactive: .testvariables mkbuilddirs boehm-gc fmil msl-external-libs lis Cdaskr CMinpack $(IPOPT_TARGET)
interactive: .testvariables mkbuilddirs boehm-gc fmil msl-external-libs lis Cdaskr CMinpack $(IPOPT_TARGET) $(UMFPACK_TARGET)
$(MAKE) -C SimulationRuntime/interactive -f $(defaultMakefileTarget)
# Depends on libinteractive.a
$(MAKE) -C SimulationRuntime/c -f $(defaultMakefileTarget)
Expand Down Expand Up @@ -115,6 +115,22 @@ build/lib/omc/libipopt.la: 3rdParty/Ipopt-3.11.6/Makefile

ipopt: build/lib/omc/libipopt.la

build/lib/omc/libumfpack.a: 3rdParty/SuiteSparse/UMFPACK/Makefile
$(MAKE) -C 3rdParty/SuiteSparse/UMFPACK
cp -a 3rdParty/SuiteSparse/UMFPACK/Lib/*.a build/lib/omc
cp -a 3rdParty/SuiteSparse/AMD/Lib/*.a build/lib/omc
mkdir --parent build/include/omc/c/suitesparse
cp -a 3rdParty/SuiteSparse/UMFPACK/Include/*.h build/include/omc/c/suitesparse
cp -a 3rdParty/SuiteSparse/AMD/Include/*.h build/include/omc/c/suitesparse
cp -a 3rdParty/SuiteSparse/UFconfig/*.h build/include/omc/c/suitesparse
umfpack: build/lib/omc/libumfpack.a

umfpack-clean:
cd 3rdParty/SuiteSparse/UMFPACK && make clean && make purge
rm -r build/include/omc/c/suitesparse
rm build/lib/omc/libumfpack.a
rm build/lib/omc/libamd.a

build/lib/omc/libopenblas_openmodelica.a:
$(MAKE) -C 3rdParty/OpenBLAS-0.2.8 CC="$(CC)" CXX="$(CXX)" FC="$(FC)" USE_THREAD=0 NO_LAPACKE=1 LIBNAMESUFFIX=openmodelica $(OPENBLAS_EXTRA_ARGS)
$(MAKE) -C 3rdParty/OpenBLAS-0.2.8 PREFIX=${abs_top_builddir}/build OPENBLAS_LIBRARY_DIR=${abs_top_builddir}/build/lib/omc OPENBLAS_INCLUDE_DIR=${abs_top_builddir}/3rdParty/build/install-includes/ NO_LAPACKE=1 LIBNAMESUFFIX=openmodelica install
Expand Down Expand Up @@ -313,7 +329,7 @@ bootstrap-clean:
openblas-clean:
# OpenBLAS make clean actually gives error-messages. Let it do it, but silently
$(MAKE) -C 3rdParty/OpenBLAS-0.2.8 clean > /dev/null 2>&1
clean: qtclean fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean
clean: qtclean fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean umfpack-clean
(cd SimulationRuntime/c && $(MAKE) -f $(defaultMakefileTarget) clean)
(cd SimulationRuntime/interactive && $(MAKE) -f $(defaultMakefileTarget) clean)
(cd Compiler && $(MAKE) -f $(defaultMakefileTarget) clean)
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Expand Up @@ -42,6 +42,7 @@ LD_LAPACK=@LD_LAPACK@
LAPACK_TARGET=@LAPACK_TARGET@
OPENBLAS_EXTRA_ARGS=@OPENBLAS_EXTRA_ARGS@
IPOPT_TARGET=ipopt
UMFPACK_TARGET=@UMFPACK_TARGET@
# We don't want the shared version, but symbols are not exported if we use the static version
# This compiles the shared and static versions, but we only copy the static version...
FMILIB_SHARED = @FMILIB_SHARED@
Expand Down
21 changes: 12 additions & 9 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -135,9 +135,11 @@ IF(Boost_LOG_FOUND AND Boost_LOG_SETUP_FOUND)
message(STATUS "Using boost log")
ELSE(Boost_LOG_FOUND AND Boost_LOG_SETUP_FOUND)
message(STATUS "Boost log disabled")
unset(Boost_LOG_LIBRARY)
ENDIF(Boost_LOG_FOUND AND Boost_LOG_SETUP_FOUND)

find_package(Boost COMPONENTS thread atomic)

SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})
find_package(Threads)
IF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
Expand All @@ -149,7 +151,6 @@ ENDIF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)

find_package(Boost COMPONENTS filesystem system serialization program_options REQUIRED)
SET(Boost_LIBRARIES_TMP ${Boost_LIBRARIES_TMP} ${Boost_LIBRARIES})

SET(Boost_LIBRARIES ${Boost_LIBRARIES_TMP})
message(STATUS "Boost Libraries")
message(STATUS ${Boost_LIBRARIES})
Expand Down Expand Up @@ -216,14 +217,16 @@ INSTALL(FILES ${SUNDIALS_LIBS} DESTINATION bin)
endif()

#Handle umfpack
#FIND_PACKAGE(SuiteSparse HINTS "${CMAKE_SOURCE_DIR}/Solver/UmfPack/")
#IF(SuiteSparse_found)
# message(STATUS "Using UmfPack")
# include_directories(${SUITESPARSE_INCLUDE_DIRS})
# add_definitions(-DUSE_UMFPACK)
#ELSE()
# message(STATUS "UmfPack disabled")
#ENDIF()
FIND_PACKAGE(SuiteSparse HINTS "${CMAKE_SOURCE_DIR}/Solver/UmfPack/")
IF(SuiteSparse_found)
message(STATUS "Using UmfPack")
include_directories(${SUITESPARSE_INCLUDE_DIRS})
add_definitions(-DUSE_UMFPACK)
SET(SUITESPARSE_INCLUDE_FLAG "-I${SUITESPARSE_INCLUDE_DIRS}")
ELSE()
message(STATUS "UmfPack disabled")
SET(SUITESPARSE_INCLUDE_FLAG "")
ENDIF()

#Mico corba
if(USE_MICO)
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/Modelica/ModelicaConfig.inc.in
Expand Up @@ -5,10 +5,9 @@ BOOST_LIBRARIES = @Boost_LIBRARIES@
BOOST_FILESYSTEM_LIB = @Boost_FILESYSTEM_LIBRARY@
BOOST_SYSTEM_LIB = @Boost_SYSTEM_LIBRARY@
BOOST_SERIALIZATION_LIB = @Boost_SERIALIZATION_LIBRARY@
BOOST_THREAD_LIB = @Boost_THREAD_LIBRARY@
BOOST_THREAD_LIB = @Boost_THREAD_LIBRARY@
BOOST_PROGRAM_OPTIONS_LIB = @Boost_PROGRAM_OPTIONS_LIBRARY@
BOOST_LOG_LIB = @Boost_LOG_LIBRARY@

SUNDIALS_LIBS = @SUNDIALS_LIBS_@
SUNDIALS_INCLUDE= @SUNDIALS_INCLUDE_DIR@
LAPACK_LIBS = @LAPACK_LIBRARIES_@
Expand All @@ -21,4 +20,5 @@ PCH_FILE = @PCH_FILE@
H_FILE = @H_FILE@
BUILD_TYPE = @BUILD_TYPE@
SYSTEM_CFLAGS = @SYSTEM_CFLAGS@
SYSTEM_CFLAGS += @SUITESPARSE_INCLUDE_FLAG@
ADDITIONAL_DEFINES = @ADDITIONAL_DEFINES@
152 changes: 37 additions & 115 deletions SimulationRuntime/cpp/Solver/UmfPack/SuiteSparseConfig.cmake
@@ -1,125 +1,47 @@
set(SuiteSparse_found true)
find_file(UMFPACK_H umfpack.h)
message(STATUS "Searching for UmfPack")
find_file(UMFPACK_H umfpack.h HINTS "${CMAKE_SOURCE_DIR}/../../build/include/omc/c/suitesparse")
if(UMFPACK_H)
get_filename_component(SUITESPARSE_INCLUDE_DIRS "${UMFPACK_H}" PATH)
get_filename_component(UMFPACK_INCLUDE_DIRS "${UMFPACK_H}" PATH)
message(STATUS "${UMFPACK_H}")
else()
message(STATUS "umfpack.h not found")
set(SuiteSparse_found false)
endif()
find_library(UMFPACK_LIB umfpack
HINTS ENV LIBRARY_PATH
HINTS "${CMAKE_SOURCE_DIR}/../../build/lib/omc"
NO_DEFAULT_PATH
DOC "The UMFPACK library")
if(UMFPACK_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${UMFPACK_LIB})
else()
message("Could not find the UMFPACK library")
set(SuiteSparse_found false)
endif()
find_package(BLAS)
if(BLAS_FOUND)
if(UMFPACK_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${UMFPACK_LIB})
else()
message(STATUS "Could not find the UMFPACK library")
set(SuiteSparse_found false)
endif()

find_package(BLAS)
if(BLAS_FOUND)
list(APPEND SUITESPARSE_LIBRARIES ${BLAS_LIBRARIES})
else()
else()
message(STATUS "Could not find the BLAS library. Please set the variable BLAS_LIBRARY to the blas library with full path")
endif()


find_library(AMD_LIB amd
HINTS ENV LIBRARY_PATH
DOC "The AMD library")
if(AMD_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${AMD_LIB})
else()
message("Could not find the AMD library.")
set(SuiteSparse_found false)
endif()
#check for if we need cholmod
set(_CHOLMOD_TEST_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/cholmodTest/)
file(WRITE ${_CHOLMOD_TEST_DIR}/CMakeLists.txt "project(cholmodTest)
cmake_minimum_required(VERSION 2.8)
include_directories(${SUITESPARSE_INCLUDE_DIRS})
add_executable(cholmodTest cholmodTest.cpp)
target_link_libraries(cholmodTest ${SUITESPARSE_LIBRARIES})")
file(WRITE ${_CHOLMOD_TEST_DIR}/cholmodTest.cpp "#include <stdio.h>
#include \"umfpack.h\"
int n = 5 ;
int Ap [ ] = {0, 2, 5, 9, 10, 12} ;
int Ai [ ] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4} ;
double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ;
double b [ ] = {8., 45., -3., 3., 19.} ;
double x [5] ;
int main (void)
{
double *null = (double *) NULL ;
int i ;
void *Symbolic, *Numeric ;
double stats [2];
umfpack_tic (stats);
(void) umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
(void) umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, null, null) ;
umfpack_di_free_symbolic (&Symbolic) ;
(void) umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, null, null) ;
umfpack_di_free_numeric (&Numeric) ;
umfpack_toc (stats);
return (0) ;
}")
# "#include <umfpack.h>
# int main(int , char* argv[]) { double c[UMFPACK_CONTROL]; umfpack_dl_defaults(c); return 0;}")
try_compile(CHOLMOD_TEST ${_CHOLMOD_TEST_DIR}/build ${_CHOLMOD_TEST_DIR} cholmodTest
OUTPUT_VARIABLE CHOLMOD_OUT)
if(NOT CHOLMOD_TEST)
file(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log "cholmodTest-output: \n ${CHOLMOD_OUT}")
find_library(CHOLMOD_LIB cholmod)
find_library(COLAMD_LIB colamd)
endif()

if(CHOLMOD_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${CHOLMOD_LIB})
else()
message("your umfpack seems to need cholmod, but cmake could not find it")
set(SuiteSparse_found false)
endif()
if(COLAMD_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${COLAMD_LIB})
else()
message("your umfpack seems to need colamd, but cmake could not find it")
set(SuiteSparse_found false)
endif()

#test with cholmod and colamd..
file(WRITE ${_CHOLMOD_TEST_DIR}/CMakeLists.txt "project(cholmodTest)
cmake_minimum_required(VERSION 2.8)
include_directories(${AMDIS_INCLUDE_DIRS})
add_executable(cholmodTest cholmodTest.cpp)
target_link_libraries(cholmodTest ${AMDIS_LIBRARIES})")
try_compile(CHOLMOD_TEST2 ${_CHOLMOD_TEST_DIR}/build ${_CHOLMOD_TEST_DIR} cholmodTest
OUTPUT_VARIABLE CHOLMOD_OUT)
if(NOT CHOLMOD_TEST2)
file(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log "cholmodTest2-output: \n ${CHOLMOD_OUT}")
find_library(SUITESPARSECONFIG_LIB suitesparseconfig)
if(SUITESPARSECONFIG_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${SUITESPARSECONFIG_LIB})
else()
message(STATUS "your umfpack seems to need suitesparseconfig, but cmake could not find it")
set(SuiteSparse_found false)
endif()
endif()
endif()
find_library(AMD_LIB amd
HINTS "${CMAKE_SOURCE_DIR}/../../build/lib/omc"
NO_DEFAULT_PATH
DOC "The AMD library")
if(AMD_LIB)
list(APPEND SUITESPARSE_LIBRARIES ${AMD_LIB})
else()
message("Could not find the AMD library.")
set(SuiteSparse_found false)
endif()

find_file(UFCONFIG_H UFconfig.h HINTS "${CMAKE_SOURCE_DIR}/../../build/include/omc/c/suitesparse")
if(UFCONFIG_H)
get_filename_component(SUITESPARSE_INCLUDE_DIRS "${UFCONFIG_H}" PATH)
else()
message(STATUS "UFconfig.h not found")
set(SuiteSparse_found false)
endif()
8 changes: 8 additions & 0 deletions configure.in
Expand Up @@ -59,6 +59,7 @@ AC_SUBST(LD_LAPACK)
AC_SUBST(PYTHON_INTERFACE)
AC_SUBST(WITH_SUNDIALS)
AC_SUBST(WITH_IPOPT)
AC_SUBST(UMFPACK_TARGET)
AC_SUBST(OMNOTEBOOK)
AC_SUBST(FPMATHFORTRAN)
AC_SUBST(OMOPTIM_CC)
Expand Down Expand Up @@ -889,6 +890,13 @@ AC_ARG_WITH(PATOH, [ --with-PATOH=DIR Compile with PATOH hyperg
USE_PATOH=0;
])

AC_ARG_WITH(UMFPACK, [ --with-UMFPACK Compile with UMFPACK, a sparse linear systems solver],
[
UMFPACK_TARGET="umfpack";
], [
UMFPACK_TARGET="";
])

AC_MSG_CHECKING([for revision])
SOURCE_REVISION=""
test -f REVISION && SOURCE_REVISION=`head -n1 REVISION | grep -o @<:@0-9@:>@@<:@0-9@:>@*`
Expand Down

0 comments on commit 02d1168

Please sign in to comment.