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 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #include "Teuchos_Assert.hpp"
33 
34 template <typename OrdinalType, typename FadType>
36 ArrayTraits(bool use_dynamic_,
37  OrdinalType workspace_size_) :
38  use_dynamic(use_dynamic_),
39  workspace_size(workspace_size_),
40  workspace(NULL),
41  workspace_pointer(NULL)
42 {
43  if (workspace_size > 0) {
44  workspace = new ValueType[workspace_size];
45  workspace_pointer = workspace;
46  }
47 }
48 
49 template <typename OrdinalType, typename FadType>
51 ArrayTraits(const ArrayTraits& a) :
52  use_dynamic(a.use_dynamic),
53  workspace_size(a.workspace_size),
54  workspace(NULL),
55  workspace_pointer(NULL)
56 {
57  if (workspace_size > 0) {
58  workspace = new ValueType*[workspace_size];
59  workspace_pointer = workspace;
60  }
61 }
62 
63 
64 template <typename OrdinalType, typename FadType>
67 {
68 // #ifdef SACADO_DEBUG
69 // TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer != workspace,
70 // std::logic_error,
71 // "ArrayTraits::~ArrayTraits(): " <<
72 // "Destructor called with non-zero used workspace. " <<
73 // "Currently used size is " << workspace_pointer-workspace <<
74 // ".");
75 
76 // #endif
77 
78  if (workspace_size > 0)
79  delete [] workspace;
80 }
81 
82 template <typename OrdinalType, typename FadType>
83 void
85 unpack() const
86 {
87 }
88 
89 template <typename OrdinalType, typename FadType>
90 void
92 pack() const
93 {
94 }
95 
96 template <typename OrdinalType, typename FadType>
97 void
99 free() const
100 {
101 }
102 
103 template <typename OrdinalType, typename FadType>
106 allocate_array(OrdinalType size) const
107 {
108  if (use_dynamic)
109  return new ValueType[size];
110 
111 #ifdef SACADO_DEBUG
112  TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer + size - workspace > workspace_size,
113  std::logic_error,
114  "ArrayTraits::allocate_array(): " <<
115  "Requested workspace memory beyond size allocated. " <<
116  "Workspace size is " << workspace_size <<
117  ", currently used is " << workspace_pointer-workspace <<
118  ", requested size is " << size << ".");
119 
120 #endif
121 
122  ValueType *v = workspace_pointer;
123  workspace_pointer += size;
124  return v;
125 }
126 
127 template <typename OrdinalType, typename FadType>
128 void
130 free_array(const ValueType* ptr, OrdinalType size) const
131 {
132  if (use_dynamic && ptr != NULL)
133  delete [] ptr;
134  else
135  workspace_pointer -= size;
136 }
137 
138 template <typename OrdinalType, typename FadType>
139 bool
141 is_array_contiguous(const FadType* a, OrdinalType n, OrdinalType n_dot) const
142 {
143  return (n > 0) &&
144  (&(a[n-1].val())-&(a[0].val()) == n-1) &&
145  (a[n-1].dx()-a[0].dx() == n-1);
146 }
147 
148 template <typename OrdinalType, typename FadType>
150 Fad_LAPACK(bool use_default_impl_,
151  bool use_dynamic_,
152  OrdinalType static_workspace_size_) :
153  arrayTraits(use_dynamic_, static_workspace_size_),
154  lapack(),
155  use_default_impl(use_default_impl_)
156 {
157 }
158 
159 template <typename OrdinalType, typename FadType>
161 Fad_LAPACK(const Fad_LAPACK& x) :
162  arrayTraits(x.arrayTraits),
163  lapack(x.lapack),
164  use_default_impl(x.use_default_impl)
165 {
166 }
167 
168 template <typename OrdinalType, typename FadType>
171 {
172 }
173 
174 template <typename OrdinalType, typename FadType>
175 void
177 GESV(const OrdinalType n, const OrdinalType nrhs, FadType* A, const OrdinalType lda,
178  OrdinalType* IPIV, FadType* B, const OrdinalType ldb, OrdinalType* info) const {
179 
180  if (use_default_impl) {
181  LAPACKType::GESV(n,nrhs,A,lda,IPIV,B,ldb,info);
182  return;
183  }
184 
185  // Unpack input values & derivatives
186  arrayTraits.unpack();
187 
188  // Call differentiated routine
189  Fad_GESV();
190 
191  // Pack values and derivatives for result
192  arrayTraits.pack();
193 
194  // Free temporary arrays
195  arrayTraits.free();
196 }
197 
198 template <typename OrdinalType, typename FadType>
199 void
201 Fad_GESV() const
202 {
203 }
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.