Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_LAPACKImp.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_Assert.hpp"
11 
12 template <typename OrdinalType, typename FadType>
14 ArrayTraits(bool use_dynamic_,
15  OrdinalType workspace_size_) :
16  use_dynamic(use_dynamic_),
17  workspace_size(workspace_size_),
18  workspace(NULL),
19  workspace_pointer(NULL)
20 {
21  if (workspace_size > 0) {
22  workspace = new ValueType[workspace_size];
23  workspace_pointer = workspace;
24  }
25 }
26 
27 template <typename OrdinalType, typename FadType>
29 ArrayTraits(const ArrayTraits& a) :
30  use_dynamic(a.use_dynamic),
31  workspace_size(a.workspace_size),
32  workspace(NULL),
33  workspace_pointer(NULL)
34 {
35  if (workspace_size > 0) {
36  workspace = new ValueType*[workspace_size];
37  workspace_pointer = workspace;
38  }
39 }
40 
41 
42 template <typename OrdinalType, typename FadType>
45 {
46 // #ifdef SACADO_DEBUG
47 // TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer != workspace,
48 // std::logic_error,
49 // "ArrayTraits::~ArrayTraits(): " <<
50 // "Destructor called with non-zero used workspace. " <<
51 // "Currently used size is " << workspace_pointer-workspace <<
52 // ".");
53 
54 // #endif
55 
56  if (workspace_size > 0)
57  delete [] workspace;
58 }
59 
60 template <typename OrdinalType, typename FadType>
61 void
63 unpack() const
64 {
65 }
66 
67 template <typename OrdinalType, typename FadType>
68 void
70 pack() const
71 {
72 }
73 
74 template <typename OrdinalType, typename FadType>
75 void
77 free() const
78 {
79 }
80 
81 template <typename OrdinalType, typename FadType>
84 allocate_array(OrdinalType size) const
85 {
86  if (use_dynamic)
87  return new ValueType[size];
88 
89 #ifdef SACADO_DEBUG
90  TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer + size - workspace > workspace_size,
91  std::logic_error,
92  "ArrayTraits::allocate_array(): " <<
93  "Requested workspace memory beyond size allocated. " <<
94  "Workspace size is " << workspace_size <<
95  ", currently used is " << workspace_pointer-workspace <<
96  ", requested size is " << size << ".");
97 
98 #endif
99 
100  ValueType *v = workspace_pointer;
101  workspace_pointer += size;
102  return v;
103 }
104 
105 template <typename OrdinalType, typename FadType>
106 void
108 free_array(const ValueType* ptr, OrdinalType size) const
109 {
110  if (use_dynamic && ptr != NULL)
111  delete [] ptr;
112  else
113  workspace_pointer -= size;
114 }
115 
116 template <typename OrdinalType, typename FadType>
117 bool
119 is_array_contiguous(const FadType* a, OrdinalType n, OrdinalType n_dot) const
120 {
121  return (n > 0) &&
122  (&(a[n-1].val())-&(a[0].val()) == n-1) &&
123  (a[n-1].dx()-a[0].dx() == n-1);
124 }
125 
126 template <typename OrdinalType, typename FadType>
128 Fad_LAPACK(bool use_default_impl_,
129  bool use_dynamic_,
130  OrdinalType static_workspace_size_) :
131  arrayTraits(use_dynamic_, static_workspace_size_),
132  lapack(),
133  use_default_impl(use_default_impl_)
134 {
135 }
136 
137 template <typename OrdinalType, typename FadType>
140  arrayTraits(x.arrayTraits),
141  lapack(x.lapack),
142  use_default_impl(x.use_default_impl)
143 {
144 }
145 
146 template <typename OrdinalType, typename FadType>
149 {
150 }
151 
152 template <typename OrdinalType, typename FadType>
153 void
155 GESV(const OrdinalType n, const OrdinalType nrhs, FadType* A, const OrdinalType lda,
156  OrdinalType* IPIV, FadType* B, const OrdinalType ldb, OrdinalType* info) const {
157 
158  if (use_default_impl) {
159  LAPACKType::GESV(n,nrhs,A,lda,IPIV,B,ldb,info);
160  return;
161  }
162 
163  // Unpack input values & derivatives
164  arrayTraits.unpack();
165 
166  // Call differentiated routine
167  Fad_GESV();
168 
169  // Pack values and derivatives for result
170  arrayTraits.pack();
171 
172  // Free temporary arrays
173  arrayTraits.free();
174 }
175 
176 template <typename OrdinalType, typename FadType>
177 void
179 Fad_GESV() const
180 {
181 }
bool is_array_contiguous(const FadType *a, OrdinalType n, OrdinalType n_dot) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ValueType * allocate_array(OrdinalType size) const
virtual ~Fad_LAPACK()
Destructor.
void GESV(const OrdinalType n, const OrdinalType nrhs, FadType *A, const OrdinalType lda, OrdinalType *IPIV, FadType *B, const OrdinalType ldb, OrdinalType *info) const
Computes the solution to a real system of linear equations.
expr val()
Fad specializations for Teuchos::LAPACK wrappers.
ArrayTraits(bool use_dynamic=true, OrdinalType workspace_size=0)
Fad_LAPACK(bool use_default_impl=true, bool use_dynamic=true, OrdinalType static_workspace_size=0)
Default constructor.
void Fad_GESV() const
Implementation of GESV.
void free_array(const ValueType *ptr, OrdinalType size) const
Base template specification for ValueType.