From 0e55f72cf7de4aa41362695ace91f855b1e166b7 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Tue, 14 Nov 2017 15:31:45 +0100 Subject: [PATCH] Detect a compiler bug that prevents compilation of complex Sacado::Rad. --- cmake/config/template-arguments.in | 15 ++++++++-- cmake/configure/configure_2_trilinos.cmake | 10 +++++-- cmake/modules/FindTRILINOS.cmake | 35 ++++++++++++++++++++++ include/deal.II/base/config.h.in | 1 + 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/cmake/config/template-arguments.in b/cmake/config/template-arguments.in index 7fb48127df..c9bcb943b7 100644 --- a/cmake/config/template-arguments.in +++ b/cmake/config/template-arguments.in @@ -24,21 +24,30 @@ DIFFERENTIABLE_ADOLC_REAL_SCALARS := { } // differentiable Sacado scalar types +DIFFERENTIABLE_TRILINOS_SACADO_REAL_SCALARS_FAD := { + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD@; + } +DIFFERENTIABLE_TRILINOS_SACADO_REAL_SCALARS_RAD := { + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD@; + } DIFFERENTIABLE_TRILINOS_SACADO_REAL_SCALARS := { - @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD@; } // differentiable scalar types DIFFERENTIABLE_REAL_SCALARS := { - @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES@; @DEAL_II_EXPAND_ADOLC_TYPES@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD@; } // all possible scalar types ALL_SCALAR_TYPES := { double; float ; std::complex; std::complex; - @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES@; @DEAL_II_EXPAND_ADOLC_TYPES@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD@; + @DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_RAD@; } // scalar types that have a corresponding MPI datatype and that we can diff --git a/cmake/configure/configure_2_trilinos.cmake b/cmake/configure/configure_2_trilinos.cmake index cf2e44eb95..8aa3c3c424 100644 --- a/cmake/configure/configure_2_trilinos.cmake +++ b/cmake/configure/configure_2_trilinos.cmake @@ -1,6 +1,6 @@ ## --------------------------------------------------------------------- ## -## Copyright (C) 2012 - 2015 by the deal.II authors +## Copyright (C) 2012 - 2017 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -206,11 +206,12 @@ MACRO(FEATURE_TRILINOS_CONFIGURE_EXTERNAL) 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 + SET(DEAL_II_EXPAND_TRILINOS_SACADO_TYPES_FAD "Sacado::Fad::DFad" "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>" @@ -219,6 +220,9 @@ MACRO(FEATURE_TRILINOS_CONFIGURE_EXTERNAL) 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}) + ENDIF() ENDMACRO() diff --git a/cmake/modules/FindTRILINOS.cmake b/cmake/modules/FindTRILINOS.cmake index a2af3c2dd0..3919f6ef33 100644 --- a/cmake/modules/FindTRILINOS.cmake +++ b/cmake/modules/FindTRILINOS.cmake @@ -173,6 +173,40 @@ IF(EXISTS ${SACADO_CMATH_HPP}) 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... # @@ -223,4 +257,5 @@ DEAL_II_PACKAGE_HANDLE(TRILINOS CLEAR TRILINOS_CONFIG_DIR EPETRA_CONFIG_H SACADO_CMATH_HPP ${_libraries} TRILINOS_SUPPORTS_CPP11 TRILINOS_HAS_C99_TR1_WORKAROUND SACADO_CONFIG_H + TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD ) diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index d3b4f309c1..72ad3e670e 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -154,6 +154,7 @@ #cmakedefine DEAL_II_USE_MT_POSIX_NO_BARRIERS /* cmake/configure/configure_2_trilinos.cmake */ +#cmakedefine DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD #cmakedefine DEAL_II_TRILINOS_WITH_ROL /* -- 2.39.5