From 4a530cc5f42cf74ddd707142fe199fe6f4fb13c1 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Tue, 10 Jul 2018 13:36:57 +0000 Subject: [PATCH] Make Sacado an optional dependency --- cmake/configure/configure_2_trilinos.cmake | 133 +++++++++++------- cmake/modules/FindTRILINOS.cmake | 99 +------------ examples/step-33/CMakeLists.txt | 6 +- include/deal.II/base/config.h.in | 1 + include/deal.II/base/numbers.h | 2 +- .../deal.II/differentiation/ad/sacado_math.h | 2 +- .../differentiation/ad/sacado_number_types.h | 2 +- .../differentiation/ad/sacado_product_types.h | 2 +- .../differentiation/ad/sacado_number_types.cc | 2 +- tests/sacado/CMakeLists.txt | 2 +- 10 files changed, 94 insertions(+), 157 deletions(-) diff --git a/cmake/configure/configure_2_trilinos.cmake b/cmake/configure/configure_2_trilinos.cmake index e8e5cff349..4f1ecbea50 100644 --- a/cmake/configure/configure_2_trilinos.cmake +++ b/cmake/configure/configure_2_trilinos.cmake @@ -42,7 +42,7 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var) ) FOREACH(_module - Amesos Epetra Ifpack AztecOO Sacado Teuchos ML MueLu + Amesos Epetra Ifpack AztecOO Teuchos ML MueLu ) ITEM_MATCHES(_module_found ${_module} ${Trilinos_PACKAGE_LIST}) IF(_module_found) @@ -66,6 +66,19 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var) ) ENDIF() + IF (${var}) + FOREACH(_optional_module ROL Sacado Zoltan) + ITEM_MATCHES(_module_found ${_optional_module} ${Trilinos_PACKAGE_LIST}) + IF(_module_found) + MESSAGE(STATUS "Found ${_optional_module}") + STRING(TOUPPER "${_optional_module}" _optional_module_upper) + SET(DEAL_II_TRILINOS_WITH_${_optional_module_upper} ON) + ELSE() + MESSAGE(STATUS "Module ${_optional_module} not found!") + ENDIF() + ENDFOREACH() + ENDIF() + # # We require at least Trilinos 12.4 # @@ -143,45 +156,63 @@ MACRO(FEATURE_TRILINOS_FIND_EXTERNAL var) SET(${var} FALSE) ENDIF() - # - # Some versions of Sacado_cmath.hpp do things that aren't compatible - # with the -std=c++0x flag of GCC, see deal.II FAQ. - # Test whether that is indeed the case - # - IF(NOT TRILINOS_SUPPORTS_CPP11) - - IF(TRILINOS_HAS_C99_TR1_WORKAROUND) - LIST(APPEND TRILINOS_DEFINITIONS "HAS_C99_TR1_CMATH") - LIST(APPEND TRILINOS_USER_DEFINITIONS "HAS_C99_TR1_CMATH") - ELSE() - MESSAGE(STATUS "Could not find a sufficient Trilinos installation: " - "The installation is not compatible with the C++ standard selected for " - "this compiler." - ) - SET(TRILINOS_ADDITIONAL_ERROR_STRING - ${TRILINOS_ADDITIONAL_ERROR_STRING} - "The Trilinos installation (found at \"${TRILINOS_DIR}\")\n" - "is not compatible with the C++ standard selected for\n" - "this compiler. See the deal.II FAQ page for a solution.\n\n" + IF(${DEAL_II_TRILINOS_WITH_SACADO}) + # + # Look for Sacado_config.h - we'll query it to determine C++11 support: + # + DEAL_II_FIND_FILE(SACADO_CONFIG_H Sacado_config.h + HINTS ${Trilinos_INCLUDE_DIRS} + NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH + ) + + IF(EXISTS ${SACADO_CONFIG_H}) + # + # Determine whether Trilinos was configured with C++11 support and + # enabling C++11 in deal.II is mandatory. + # + FILE(STRINGS "${SACADO_CONFIG_H}" SACADO_CXX11_STRING + REGEX "#define HAVE_SACADO_CXX11") + ENDIF() + + # + # GCC 6.3.0 has a bug that prevents the creation of complex + # numbers templated on Sacado::Rad::ADvar types: + # + # include/c++/6.3.0/complex: In instantiation of + # ‘struct std::complex >’: + # include/c++/6.3.0/complex:206:16: error: ‘std::complex<_Tp>& std::complex<_Tp>::operator=(const std::complex<_Tp>&) [with _Tp = Sacado::Rad::ADvar]’ declared to take const reference, but implicit declaration would take non-const + # + # Test whether the compiler hits this issue + # + DEAL_II_FIND_FILE(SACADO_TRAD_HPP Sacado_trad.hpp + HINTS ${Trilinos_INCLUDE_DIRS} + NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH + ) + + IF(EXISTS ${SACADO_TRAD_HPP}) + LIST(APPEND CMAKE_REQUIRED_INCLUDES ${Trilinos_INCLUDE_DIRS}) + PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}") + + CHECK_CXX_SOURCE_COMPILES( + " + #include + int main () + { + Sacado::Rad::ADvar sacado_rad_double; // Works + std::complex > complex_sacado_rad_double; // Doesn't work + return 0; + } + " + TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD ) - SET(${var} FALSE) + RESET_CMAKE_REQUIRED() ENDIF() + ENDIF() CHECK_MPI_INTERFACE(TRILINOS ${var}) - - IF (${var}) - FOREACH(_optional_module ROL Zoltan) - ITEM_MATCHES(_module_found ${_optional_module} ${Trilinos_PACKAGE_LIST}) - IF(_module_found) - MESSAGE(STATUS "Found ${_optional_module}") - STRING(TOUPPER "${_optional_module}" _optional_module_upper) - SET(DEAL_II_TRILINOS_WITH_${_optional_module_upper} ON) - ELSE() - MESSAGE(STATUS "Module ${_optional_module} not found!") - ENDIF() - ENDFOREACH() - ENDIF() ENDIF() ENDMACRO() @@ -194,24 +225,26 @@ MACRO(FEATURE_TRILINOS_CONFIGURE_EXTERNAL) "TrilinosWrappers::BlockSparseMatrix") SET(DEAL_II_EXPAND_TRILINOS_MPI_BLOCKVECTOR "TrilinosWrappers::MPI::BlockVector") SET(DEAL_II_EXPAND_TRILINOS_MPI_VECTOR "TrilinosWrappers::MPI::Vector") - # Note: Only CMake 3.0 and greater support line continuation with the "\" character - # Elements of string lists are naturally separated by a ";" - SET(DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD - "Sacado::Fad::DFad" - "Sacado::Fad::DFad" - "Sacado::Fad::DFad>" - "Sacado::Fad::DFad>") - SET(DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD - "Sacado::Rad::ADvar" - "Sacado::Rad::ADvar" - "Sacado::Rad::ADvar>" - "Sacado::Rad::ADvar>") - IF (TRILINOS_WITH_MPI) SET(DEAL_II_EXPAND_EPETRA_VECTOR "LinearAlgebra::EpetraWrappers::Vector") ENDIF() - IF (TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD) - SET(DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD ${TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD}) + IF(${DEAL_II_TRILINOS_WITH_SACADO}) + # Note: Only CMake 3.0 and greater support line continuation with the "\" character + # Elements of string lists are naturally separated by a ";" + SET(DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD + "Sacado::Fad::DFad" + "Sacado::Fad::DFad" + "Sacado::Fad::DFad>" + "Sacado::Fad::DFad>") + SET(DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD + "Sacado::Rad::ADvar" + "Sacado::Rad::ADvar" + "Sacado::Rad::ADvar>" + "Sacado::Rad::ADvar>") + + IF (TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD) + SET(DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD ${TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD}) + ENDIF() ENDIF() ENDMACRO() diff --git a/cmake/modules/FindTRILINOS.cmake b/cmake/modules/FindTRILINOS.cmake index ce656553db..a0021b3398 100644 --- a/cmake/modules/FindTRILINOS.cmake +++ b/cmake/modules/FindTRILINOS.cmake @@ -25,11 +25,7 @@ # TRILINOS_VERSION_MAJOR # TRILINOS_VERSION_MINOR # TRILINOS_VERSION_SUBMINOR -# TRILINOS_WITH_MANDATORY_CXX11 # TRILINOS_WITH_MPI -# TRILINOS_SUPPORTS_CPP11 -# TRILINOS_HAS_C99_TR1_WORKAROUND -# TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD # SET(TRILINOS_DIR "" CACHE PATH "An optional hint to a Trilinos installation") @@ -114,99 +110,6 @@ IF(EXISTS ${EPETRA_CONFIG_H}) ENDIF() ENDIF() -# -# Look for Sacado_config.h - we'll query it to determine C++11 support: -# -DEAL_II_FIND_FILE(SACADO_CONFIG_H Sacado_config.h - HINTS ${Trilinos_INCLUDE_DIRS} - NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH - ) - -SET(TRILINOS_WITH_MANDATORY_CXX11 FALSE) -IF(EXISTS ${SACADO_CONFIG_H}) - # - # Determine whether Trilinos was configured with C++11 support and - # enabling C++11 in deal.II is mandatory. - # - FILE(STRINGS "${SACADO_CONFIG_H}" SACADO_CXX11_STRING - REGEX "#define HAVE_SACADO_CXX11") - IF(NOT "${SACADO_CXX11_STRING}" STREQUAL "") - SET(TRILINOS_WITH_MANDATORY_CXX11 TRUE) - ENDIF() -ENDIF() - -# -# Some versions of Sacado_cmath.hpp do things that aren't compatible -# with the -std=c++0x flag of GCC, see deal.II FAQ. -# Test whether that is indeed the case: -# - -DEAL_II_FIND_FILE(SACADO_CMATH_HPP Sacado_cmath.hpp - HINTS ${Trilinos_INCLUDE_DIRS} - NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH - ) - -IF(EXISTS ${SACADO_CMATH_HPP}) - LIST(APPEND CMAKE_REQUIRED_INCLUDES ${Trilinos_INCLUDE_DIRS}) - PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}") - - CHECK_CXX_SOURCE_COMPILES( - " - #include - int main(){ return 0; } - " - TRILINOS_SUPPORTS_CPP11 - ) - - # - # Try whether exporting HAS_C99_TR1_CMATH helps: - # - PUSH_CMAKE_REQUIRED("-DHAS_C99_TR1_CMATH") - CHECK_CXX_SOURCE_COMPILES( - " - #include - int main(){ return 0; } - " - TRILINOS_HAS_C99_TR1_WORKAROUND - ) - RESET_CMAKE_REQUIRED() -ENDIF() - -# -# GCC 6.3.0 has a bug that prevents the creation of complex -# numbers templated on Sacado::Rad::ADvar types: -# -# include/c++/6.3.0/complex: In instantiation of ‘struct std::complex >’: -# include/c++/6.3.0/complex:206:16: error: ‘std::complex<_Tp>& std::complex<_Tp>::operator=(const std::complex<_Tp>&) [with _Tp = Sacado::Rad::ADvar]’ declared to take const reference, but implicit declaration would take non-const -# -# Test whether the compiler hits this issue -# -DEAL_II_FIND_FILE(SACADO_TRAD_HPP Sacado_trad.hpp - HINTS ${Trilinos_INCLUDE_DIRS} - NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH - ) - -IF(EXISTS ${SACADO_TRAD_HPP}) - LIST(APPEND CMAKE_REQUIRED_INCLUDES ${Trilinos_INCLUDE_DIRS}) - PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}") - - CHECK_CXX_SOURCE_COMPILES( - " - #include - int main () - { - Sacado::Rad::ADvar sacado_rad_double; // Works - std::complex > complex_sacado_rad_double; // Doesn't work - return 0; - } - " - TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD - ) - RESET_CMAKE_REQUIRED() -ENDIF() # # *Boy* Sanitize variables that are exported by TrilinosConfig.cmake... @@ -257,6 +160,6 @@ DEAL_II_PACKAGE_HANDLE(TRILINOS OPTIONAL Trilinos_TPL_INCLUDE_DIRS CLEAR TRILINOS_CONFIG_DIR EPETRA_CONFIG_H SACADO_CMATH_HPP ${_libraries} - TRILINOS_SUPPORTS_CPP11 TRILINOS_HAS_C99_TR1_WORKAROUND SACADO_CONFIG_H + SACADO_CONFIG_H TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD ) diff --git a/examples/step-33/CMakeLists.txt b/examples/step-33/CMakeLists.txt index 59ae8864de..a00a050041 100644 --- a/examples/step-33/CMakeLists.txt +++ b/examples/step-33/CMakeLists.txt @@ -40,12 +40,12 @@ ENDIF() # # Are all dependencies fulfilled? # -IF(NOT DEAL_II_WITH_TRILINOS) # keep in one line +IF(NOT DEAL_II_TRILINOS_WITH_SACADO) # keep in one line MESSAGE(FATAL_ERROR " Error! This tutorial requires a deal.II library that was configured with the following options: - DEAL_II_WITH_TRILINOS = ON + DEAL_II_TRILINOS_WITH_SACADO = ON However, the deal.II library found at ${DEAL_II_PATH} was configured with these options - DEAL_II_WITH_TRILINOS = ${DEAL_II_WITH_TRILINOS} + DEAL_II_TRILINOS_WITH_SACADO = ${DEAL_II_TRILINOS_WITH_SACADO} which conflict with the requirements." ) ENDIF() diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 3b5609d1e7..717ca8b897 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -163,6 +163,7 @@ /* cmake/configure/configure_2_trilinos.cmake */ #cmakedefine DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD #cmakedefine DEAL_II_TRILINOS_WITH_ROL +#cmakedefine DEAL_II_TRILINOS_WITH_SACADO #cmakedefine DEAL_II_TRILINOS_WITH_ZOLTAN diff --git a/include/deal.II/base/numbers.h b/include/deal.II/base/numbers.h index db7c151643..5123c9ed12 100644 --- a/include/deal.II/base/numbers.h +++ b/include/deal.II/base/numbers.h @@ -53,7 +53,7 @@ DEAL_II_NAMESPACE_CLOSE // but header indirectly references numbers.h. We therefore simply // import the whole Sacado header at this point to get the math // functions imported into the standard namespace. -#ifdef DEAL_II_WITH_TRILINOS +#ifdef DEAL_II_TRILINOS_WITH_SACADO # include #endif diff --git a/include/deal.II/differentiation/ad/sacado_math.h b/include/deal.II/differentiation/ad/sacado_math.h index 2b446c8f9f..53b6bedf96 100644 --- a/include/deal.II/differentiation/ad/sacado_math.h +++ b/include/deal.II/differentiation/ad/sacado_math.h @@ -18,7 +18,7 @@ #include -#ifdef DEAL_II_WITH_TRILINOS +#ifdef DEAL_II_TRILINOS_WITH_SACADO # include diff --git a/include/deal.II/differentiation/ad/sacado_number_types.h b/include/deal.II/differentiation/ad/sacado_number_types.h index 5139fce830..44970b1117 100644 --- a/include/deal.II/differentiation/ad/sacado_number_types.h +++ b/include/deal.II/differentiation/ad/sacado_number_types.h @@ -71,7 +71,7 @@ DEAL_II_NAMESPACE_CLOSE -#ifdef DEAL_II_WITH_TRILINOS +#ifdef DEAL_II_TRILINOS_WITH_SACADO DEAL_II_DISABLE_EXTRA_DIAGNOSTICS # include diff --git a/include/deal.II/differentiation/ad/sacado_product_types.h b/include/deal.II/differentiation/ad/sacado_product_types.h index e4faee3510..cd8ea8bedc 100644 --- a/include/deal.II/differentiation/ad/sacado_product_types.h +++ b/include/deal.II/differentiation/ad/sacado_product_types.h @@ -20,7 +20,7 @@ #include -#ifdef DEAL_II_WITH_TRILINOS +#ifdef DEAL_II_TRILINOS_WITH_SACADO # include // It appears that some versions of Trilinos do not directly or indirectly diff --git a/source/differentiation/ad/sacado_number_types.cc b/source/differentiation/ad/sacado_number_types.cc index ec2a10b511..582a74d6db 100644 --- a/source/differentiation/ad/sacado_number_types.cc +++ b/source/differentiation/ad/sacado_number_types.cc @@ -16,7 +16,7 @@ #include -#ifdef DEAL_II_WITH_TRILINOS +#ifdef DEAL_II_TRILINOS_WITH_SACADO # include diff --git a/tests/sacado/CMakeLists.txt b/tests/sacado/CMakeLists.txt index d2d115e821..6186bb48d9 100644 --- a/tests/sacado/CMakeLists.txt +++ b/tests/sacado/CMakeLists.txt @@ -1,6 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) INCLUDE(../setup_testsubproject.cmake) PROJECT(testsuite CXX) -IF(DEAL_II_WITH_TRILINOS) +IF(DEAL_II_WITH_TRILINOS AND DEAL_II_TRILINOS_WITH_SACADO) DEAL_II_PICKUP_TESTS() ENDIF() -- 2.39.5