https://mooseframework.inl.gov
KokkosUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "KokkosHeader.h"
13 
14 namespace Moose
15 {
16 namespace Kokkos
17 {
18 namespace Utils
19 {
20 
28 template <typename T>
29 KOKKOS_INLINE_FUNCTION const T *
30 find(const T & target, const T * const begin, const T * const end)
31 {
32  if (begin == end)
33  return end;
34 
35  auto left = begin;
36  auto right = end - 1;
37 
38  while (left <= right)
39  {
40  auto mid = left + (right - left) / 2;
41 
42  if (*mid == target)
43  return mid;
44  else if (*mid < target)
45  left = mid + 1;
46  else
47  right = mid - 1;
48  }
49 
50  return end;
51 }
52 
61 KOKKOS_INLINE_FUNCTION void
62 choleskySolve(Real * const A, Real * const x, Real * const b, const unsigned int n)
63 {
64  for (unsigned int i = 0; i < n; ++i)
65  {
66  for (unsigned int j = 0; j <= i; ++j)
67  {
68  Real sum = A[j + n * i];
69 
70  for (unsigned int k = 0; k < j; ++k)
71  sum -= A[k + n * i] * A[k + n * j];
72 
73  if (i == j)
74  A[j + n * i] = ::Kokkos::sqrt(sum);
75  else
76  A[j + n * i] = sum / A[j + n * j];
77  }
78  }
79 
80  for (unsigned int i = 0; i < n; ++i)
81  {
82  Real sum = b[i];
83 
84  for (unsigned int j = 0; j < i; ++j)
85  sum -= A[j + n * i] * b[j];
86 
87  b[i] = sum / A[i + n * i];
88  }
89 
90  for (int i = n - 1; i >= 0; --i)
91  {
92  Real sum = b[i];
93 
94  for (unsigned int j = i + 1; j < n; ++j)
95  sum -= A[i + n * j] * b[j];
96 
97  x[i] = sum / A[i + n * i];
98  }
99 }
100 
101 } // namespace Utils
102 } // namespace Kokkos
103 } // namespace Moose
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:30
KOKKOS_INLINE_FUNCTION void choleskySolve(Real *const A, Real *const x, Real *const b, const unsigned int n)
Perform an in-place linear solve using Cholesky decomposition Matrix and right-hand-side vector are m...
Definition: KokkosUtils.h:62
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...