Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_Fad_LAPACKImp.hpp
Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #include "Teuchos_Assert.hpp"
00033 
00034 template <typename OrdinalType, typename FadType>
00035 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00036 ArrayTraits(bool use_dynamic_, 
00037       OrdinalType workspace_size_) : 
00038   use_dynamic(use_dynamic_),
00039   workspace_size(workspace_size_),
00040   workspace(NULL),
00041   workspace_pointer(NULL)
00042 {
00043   if (workspace_size > 0) {
00044     workspace = new ValueType[workspace_size];
00045     workspace_pointer = workspace;
00046   }
00047 }
00048 
00049 template <typename OrdinalType, typename FadType>
00050 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00051 ArrayTraits(const ArrayTraits& a) :
00052   use_dynamic(a.use_dynamic),
00053   workspace_size(a.workspace_size),
00054   workspace(NULL),
00055   workspace_pointer(NULL)
00056 {
00057   if (workspace_size > 0) {
00058     workspace = new ValueType*[workspace_size];
00059     workspace_pointer = workspace;
00060   }
00061 }
00062   
00063 
00064 template <typename OrdinalType, typename FadType>
00065 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00066 ~ArrayTraits()
00067 {
00068 // #ifdef SACADO_DEBUG
00069 //   TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer != workspace,
00070 //         std::logic_error,
00071 //         "ArrayTraits::~ArrayTraits(): " <<
00072 //         "Destructor called with non-zero used workspace. " <<
00073 //         "Currently used size is " << workspace_pointer-workspace <<
00074 //         ".");
00075     
00076 // #endif
00077 
00078   if (workspace_size > 0)
00079     delete [] workspace;
00080 }
00081 
00082 template <typename OrdinalType, typename FadType>
00083 void
00084 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00085 unpack() const
00086 {
00087 }
00088 
00089 template <typename OrdinalType, typename FadType>
00090 void
00091 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00092 pack() const
00093 {
00094 }
00095 
00096 template <typename OrdinalType, typename FadType>
00097 void
00098 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00099 free() const
00100 {
00101 }
00102 
00103 template <typename OrdinalType, typename FadType>
00104 typename Sacado::Fad::ArrayTraits<OrdinalType,FadType>::ValueType*
00105 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00106 allocate_array(OrdinalType size) const
00107 {
00108   if (use_dynamic)
00109     return new ValueType[size];
00110 
00111 #ifdef SACADO_DEBUG
00112   TEUCHOS_TEST_FOR_EXCEPTION(workspace_pointer + size - workspace > workspace_size,
00113          std::logic_error,
00114          "ArrayTraits::allocate_array(): " <<
00115          "Requested workspace memory beyond size allocated. " <<
00116          "Workspace size is " << workspace_size << 
00117          ", currently used is " << workspace_pointer-workspace << 
00118          ", requested size is " << size << ".");
00119     
00120 #endif
00121 
00122   ValueType *v = workspace_pointer;
00123   workspace_pointer += size;
00124   return v;
00125 }
00126 
00127 template <typename OrdinalType, typename FadType>
00128 void
00129 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00130 free_array(const ValueType* ptr, OrdinalType size) const
00131 {
00132   if (use_dynamic && ptr != NULL)
00133     delete [] ptr;
00134   else
00135     workspace_pointer -= size;
00136 }
00137 
00138 template <typename OrdinalType, typename FadType>
00139 bool
00140 Sacado::Fad::ArrayTraits<OrdinalType,FadType>::
00141 is_array_contiguous(const FadType* a, OrdinalType n, OrdinalType n_dot) const
00142 {
00143   return (n > 0) && 
00144     (&(a[n-1].val())-&(a[0].val()) == n-1) && 
00145     (a[n-1].dx()-a[0].dx() == n-1);
00146 }
00147 
00148 template <typename OrdinalType, typename FadType>
00149 Sacado::Fad::Fad_LAPACK<OrdinalType,FadType>::
00150 Fad_LAPACK(bool use_default_impl_,
00151            bool use_dynamic_, 
00152            OrdinalType static_workspace_size_) : 
00153   LAPACKType(),
00154   arrayTraits(use_dynamic_, static_workspace_size_),
00155   lapack(),
00156   use_default_impl(use_default_impl_)
00157 {
00158 }
00159 
00160 template <typename OrdinalType, typename FadType>
00161 Sacado::Fad::Fad_LAPACK<OrdinalType,FadType>::
00162 Fad_LAPACK(const Fad_LAPACK& x) : 
00163   LAPACKType(x),
00164   arrayTraits(x.arrayTraits),
00165   lapack(x.lapack),
00166   use_default_impl(x.use_default_impl) 
00167 {
00168 }
00169 
00170 template <typename OrdinalType, typename FadType>
00171 Sacado::Fad::Fad_LAPACK<OrdinalType,FadType>::
00172 ~Fad_LAPACK() 
00173 {
00174 }
00175 
00176 template <typename OrdinalType, typename FadType>
00177 void
00178 Sacado::Fad::Fad_LAPACK<OrdinalType,FadType>::
00179 GESV(const OrdinalType n, const OrdinalType nrhs, FadType* A, const OrdinalType lda,
00180      OrdinalType* IPIV, FadType* B, const OrdinalType ldb, OrdinalType* info) const {
00181 
00182   if (use_default_impl) {
00183     LAPACKType::GESV(n,nrhs,A,lda,IPIV,B,ldb,info);
00184     return;
00185   }
00186 
00187   // Unpack input values & derivatives
00188   arrayTraits.unpack();
00189 
00190   // Call differentiated routine
00191   Fad_GESV();
00192   
00193   // Pack values and derivatives for result
00194   arrayTraits.pack();
00195   
00196   // Free temporary arrays
00197   arrayTraits.free();
00198 }
00199 
00200 template <typename OrdinalType, typename FadType>
00201 void
00202 Sacado::Fad::Fad_LAPACK<OrdinalType,FadType>::
00203 Fad_GESV() const
00204 {
00205 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines