From 3e99566dd39f8ab70aa366c542a3bb192020e9cb Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 1 Aug 2014 12:27:11 +0200 Subject: [PATCH] Use OpenBLAS instead of BLAS if available. OpenBLAS is an optimized BLAS library. --- CMakeLists.txt | 23 +++++++++++++++++------ cmake/Modules/FindOpenBLAS.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 cmake/Modules/FindOpenBLAS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e6750c33..d2941e964 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -562,9 +562,10 @@ endif(DOXYGEN_FOUND) ################################################################################ if(OS_IS_LINUX) - ############################################# + ############################################################################# # Check that LAPACK is found in the system - ############################################# + # LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse. + ############################################################################# find_library(LAPACK lapack) if(NOT LAPACK) message(" The LAPACK library has not been found.") @@ -578,9 +579,11 @@ if(OS_IS_LINUX) endif(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") message(FATAL_ERROR "LAPACK is required to build gnss-sdr") endif(NOT LAPACK) - ############################################# + ############################################################################# # Check that BLAS is found in the system - ############################################# + # BLAS is used for matrix multiplication. + #ÊWithout BLAS, matrix multiplication will still work, but might be slower. + ############################################################################# find_library(BLAS blas) if(NOT BLAS) message(" The BLAS library has not been found.") @@ -668,7 +671,11 @@ if(NOT ARMADILLO_FOUND) "12c12 < // #define ARMA_USE_LAPACK --- -> #define ARMA_USE_LAPACK +> #define ARMA_USE_LAPACK +19c19 +< // #define ARMA_USE_BLAS +--- +> #define ARMA_USE_BLAS ") endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/download/armadillo-${armadillo_RELEASE}/armadillo-${armadillo_RELEASE}.tar.gz) ExternalProject_Add( @@ -689,7 +696,11 @@ if(NOT ARMADILLO_FOUND) ExternalProject_Get_Property(armadillo-${armadillo_RELEASE} binary_dir) set(ARMADILLO_INCLUDE_DIRS ${binary_dir}/include ) find_library(LAPACK NAMES lapack HINTS /usr/lib /usr/local/lib /usr/lib64) - set(ARMADILLO_LIBRARIES ${LAPACK} ${GFORTRAN} ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}armadillo.a) + find_package(OpenBLAS) + if(OPENBLAS_FOUND) + set(BLAS OPENBLAS) + endif(OPENBLAS_FOUND) + set(ARMADILLO_LIBRARIES ${BLAS} ${LAPACK} ${GFORTRAN} ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}armadillo.a) set(LOCAL_ARMADILLO true CACHE STRING "Armadillo downloaded and built automatically" FORCE) # Save a copy at the thirdparty folder file(COPY ${CMAKE_CURRENT_BINARY_DIR}/armadillo-${armadillo_RELEASE} diff --git a/cmake/Modules/FindOpenBLAS.cmake b/cmake/Modules/FindOpenBLAS.cmake new file mode 100644 index 000000000..d8751b216 --- /dev/null +++ b/cmake/Modules/FindOpenBLAS.cmake @@ -0,0 +1,25 @@ +# - Try to find OpenBLAS library (not headers!) +# +# The following environment variable is optionally searched +# OPENBLAS_HOME: Base directory where all OpenBlas components are found + +SET(OPEN_BLAS_SEARCH_PATHS /lib/ + /lib64/ + /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /opt/OpenBLAS/lib + /opt/local/lib + /usr/lib/openblas-base + $ENV{OPENBLAS_HOME}/lib + ) + +FIND_LIBRARY(OPENBLAS NAMES openblas PATHS ${OPEN_BLAS_SEARCH_PATHS}) + +IF (OPENBLAS) + SET(OPENBLAS_FOUND ON) + MESSAGE(STATUS "Found OpenBLAS") +ENDIF (OPENBLAS) + +MARK_AS_ADVANCED(OPENBLAS)