From: Jean-Paul Pelteret Date: Sun, 16 May 2021 07:22:21 +0000 (+0200) Subject: Add variant of vectorized pow() X-Git-Tag: v9.3.0-rc1~48^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df7cd471a0903006e32008bb81351aff25996d09;p=dealii.git Add variant of vectorized pow() --- diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index 851a2f2b07..b780aa5517 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -5432,6 +5432,30 @@ namespace std + /** + * Raises the given number @p x to the power @p p for a vectorized data + * field. The result is returned as vectorized array in the form + * {pow(x[0],p[0]), pow(x[1],p[1]), ..., + * pow(x[size()-1],p[size()-1])}. + * + * @relatesalso VectorizedArray + */ + template + inline ::dealii::VectorizedArray + pow(const ::dealii::VectorizedArray &x, + const ::dealii::VectorizedArray &p) + { + Number values[::dealii::VectorizedArray::size()]; + for (unsigned int i = 0; i < dealii::VectorizedArray::size(); + ++i) + values[i] = std::pow(x[i], p[i]); + ::dealii::VectorizedArray out; + out.load(&values[0]); + return out; + } + + + /** * Compute the absolute value (modulus) of a vectorized data field. The * result is returned as vectorized array in the form {abs(x[0]), diff --git a/tests/base/vectorization_13.cc b/tests/base/vectorization_13.cc index 535cf8211d..a85dfae652 100644 --- a/tests/base/vectorization_13.cc +++ b/tests/base/vectorization_13.cc @@ -37,6 +37,21 @@ do_test(const VectorizedArrayType array, } +template +void +do_test(const VectorizedArrayType array, const VectorizedArrayType number) +{ + deallog << " test " << VectorizedArrayType::size() << " array elements" + << std::endl; + + auto exponentiated_array = std::pow(array, number); + + for (unsigned int i = 0; i < VectorizedArrayType::size(); i++) + deallog << exponentiated_array[i] << " "; + deallog << std::endl; +} + + int main() { @@ -45,18 +60,30 @@ main() #if DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 512 do_test(VectorizedArray(2.0), 3.0); do_test(VectorizedArray(2.0), 3.0); + + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); #endif #if DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 256 do_test(VectorizedArray(2.0), 3.0); do_test(VectorizedArray(2.0), 3.0); + + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); #endif #if DEAL_II_VECTORIZATION_WIDTH_IN_BITS >= 128 do_test(VectorizedArray(2.0), 3.0); do_test(VectorizedArray(2.0), 3.0); + + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); #endif do_test(VectorizedArray(2.0), 3.0); do_test(VectorizedArray(2.0), 3.0); + + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); + do_test(VectorizedArray(2.0), VectorizedArray(3.0)); } diff --git a/tests/base/vectorization_13.output b/tests/base/vectorization_13.output index b255be5f41..0256affa8a 100644 --- a/tests/base/vectorization_13.output +++ b/tests/base/vectorization_13.output @@ -3,3 +3,7 @@ DEAL:: test 1 array elements DEAL::8.00000 DEAL:: test 1 array elements DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 diff --git a/tests/base/vectorization_13.output.avx b/tests/base/vectorization_13.output.avx index e8cc787586..358a166d55 100644 --- a/tests/base/vectorization_13.output.avx +++ b/tests/base/vectorization_13.output.avx @@ -3,6 +3,14 @@ DEAL:: test 4 array elements DEAL::8.00000 8.00000 8.00000 8.00000 DEAL:: test 8 array elements DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 +DEAL:: test 4 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 8 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 +DEAL:: test 2 array elements +DEAL::8.00000 8.00000 +DEAL:: test 4 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 DEAL:: test 2 array elements DEAL::8.00000 8.00000 DEAL:: test 4 array elements @@ -11,3 +19,7 @@ DEAL:: test 1 array elements DEAL::8.00000 DEAL:: test 1 array elements DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 diff --git a/tests/base/vectorization_13.output.avx512 b/tests/base/vectorization_13.output.avx512 index 46df357ef7..f11346db8c 100644 --- a/tests/base/vectorization_13.output.avx512 +++ b/tests/base/vectorization_13.output.avx512 @@ -1,4 +1,8 @@ +DEAL:: test 8 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 +DEAL:: test 16 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 DEAL:: test 8 array elements DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 DEAL:: test 16 array elements @@ -7,10 +11,22 @@ DEAL:: test 4 array elements DEAL::8.00000 8.00000 8.00000 8.00000 DEAL:: test 8 array elements DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 +DEAL:: test 4 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 8 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 8.00000 DEAL:: test 2 array elements DEAL::8.00000 8.00000 DEAL:: test 4 array elements DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 2 array elements +DEAL::8.00000 8.00000 +DEAL:: test 4 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 DEAL:: test 1 array elements DEAL::8.00000 DEAL:: test 1 array elements diff --git a/tests/base/vectorization_13.output.sse2 b/tests/base/vectorization_13.output.sse2 index 33e4e4f81a..a74598cedc 100644 --- a/tests/base/vectorization_13.output.sse2 +++ b/tests/base/vectorization_13.output.sse2 @@ -3,6 +3,14 @@ DEAL:: test 2 array elements DEAL::8.00000 8.00000 DEAL:: test 4 array elements DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 2 array elements +DEAL::8.00000 8.00000 +DEAL:: test 4 array elements +DEAL::8.00000 8.00000 8.00000 8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 +DEAL:: test 1 array elements +DEAL::8.00000 DEAL:: test 1 array elements DEAL::8.00000 DEAL:: test 1 array elements