From: Wolfgang Bangerth Date: Tue, 9 Jan 2024 20:39:34 +0000 (-0700) Subject: Move a function definition to the bottom of the file. X-Git-Tag: relicensing~182^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6c3fce0572f6505dc75d8ba78df35167d048750;p=dealii.git Move a function definition to the bottom of the file. --- diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index 5c5a1252ec..87c1ffef5c 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -437,7 +437,6 @@ namespace Utilities T fixed_power(const T t); - /** * A replacement for std::pow that allows compile-time * calculations for constant expression arguments and if the exponent @@ -447,58 +446,7 @@ namespace Utilities */ template >> constexpr DEAL_II_HOST_DEVICE T - pow(const T base, const int iexp) - { -#if defined(DEBUG) && !defined(DEAL_II_CXX14_CONSTEXPR_BUG) - // Up to __builtin_expect this is the same code as in the 'Assert' macro. - // The call to __builtin_expect turns out to be problematic. -# if KOKKOS_VERSION >= 30600 - KOKKOS_IF_ON_HOST(({ - if (!(iexp >= 0)) - ::dealii::deal_II_exceptions::internals::issue_error_noreturn( - ::dealii::deal_II_exceptions::internals::ExceptionHandling:: - abort_or_throw_on_exception, - __FILE__, - __LINE__, - __PRETTY_FUNCTION__, - "iexp>=0", - "ExcMessage(\"The exponent must not be negative!\")", - ExcMessage("The exponent must not be negative!")); - })) -# else -# ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST - if (!(iexp >= 0)) - ::dealii::deal_II_exceptions::internals::issue_error_noreturn( - ::dealii::deal_II_exceptions::internals::ExceptionHandling:: - abort_or_throw_on_exception, - __FILE__, - __LINE__, - __PRETTY_FUNCTION__, - "iexp>=0", - "ExcMessage(\"The exponent must not be negative!\")", - ExcMessage("The exponent must not be negative!")); -# endif -# endif -#endif - // The "exponentiation by squaring" algorithm used below has to be expressed - // in an iterative version since SYCL doesn't allow recursive functions used - // in device code. - - if (iexp <= 0) - return 1; - - int exp = iexp; - T x = base; - T y = 1; - while (exp > 1) - { - if (exp % 2 == 1) - y *= x; - x *= x; - exp /= 2; - } - return x * y; - } + pow(const T base, const int iexp); /** * Optimized replacement for std::lower_bound for searching within @@ -525,7 +473,6 @@ namespace Utilities Iterator lower_bound(Iterator first, Iterator last, const T &val); - /** * The same function as above, but taking an argument that is used to * compare individual elements of the sequence of objects pointed to by the @@ -995,6 +942,63 @@ namespace Utilities + template + constexpr DEAL_II_HOST_DEVICE T + pow(const T base, const int iexp) + { +#if defined(DEBUG) && !defined(DEAL_II_CXX14_CONSTEXPR_BUG) + // Up to __builtin_expect this is the same code as in the 'Assert' macro. + // The call to __builtin_expect turns out to be problematic. +# if KOKKOS_VERSION >= 30600 + KOKKOS_IF_ON_HOST(({ + if (!(iexp >= 0)) + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: + abort_or_throw_on_exception, + __FILE__, + __LINE__, + __PRETTY_FUNCTION__, + "iexp>=0", + "ExcMessage(\"The exponent must not be negative!\")", + ExcMessage("The exponent must not be negative!")); + })) +# else +# ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST + if (!(iexp >= 0)) + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( + ::dealii::deal_II_exceptions::internals::ExceptionHandling:: + abort_or_throw_on_exception, + __FILE__, + __LINE__, + __PRETTY_FUNCTION__, + "iexp>=0", + "ExcMessage(\"The exponent must not be negative!\")", + ExcMessage("The exponent must not be negative!")); +# endif +# endif +#endif + // The "exponentiation by squaring" algorithm used below has to be expressed + // in an iterative version since SYCL doesn't allow recursive functions used + // in device code. + + if (iexp <= 0) + return 1; + + int exp = iexp; + T x = base; + T y = 1; + while (exp > 1) + { + if (exp % 2 == 1) + y *= x; + x *= x; + exp /= 2; + } + return x * y; + } + + + template inline std::string type_to_string(const T &t)