|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include <assert.h> 00030 00031 #include "AbstractLinAlgPack_MultiVectorMutableDense.hpp" 00032 #include "AbstractLinAlgPack_VectorMutableDense.hpp" 00033 #include "AbstractLinAlgPack_MatrixSymOpGetGMSSymMutable.hpp" 00034 #include "AbstractLinAlgPack_SpVectorOp.hpp" 00035 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp" 00036 #include "DenseLinAlgPack_DMatrixOut.hpp" 00037 #include "ReleaseResource_ref_count_ptr.hpp" 00038 #include "Teuchos_Workspace.hpp" 00039 #include "Teuchos_TestForException.hpp" 00040 00041 namespace AbstractLinAlgPack { 00042 00043 // Constructors / initializers 00044 00045 MultiVectorMutableDense::MultiVectorMutableDense( 00046 const size_type rows 00047 ,const size_type cols 00048 ) 00049 { 00050 this->initialize(rows,cols); 00051 } 00052 00053 MultiVectorMutableDense::MultiVectorMutableDense( 00054 DMatrixSlice gms 00055 ,BLAS_Cpp::Transp gms_trans 00056 ,const release_resource_ptr_t& gms_release 00057 ) 00058 { 00059 this->initialize(gms,gms_trans,gms_release); 00060 } 00061 00062 void MultiVectorMutableDense::initialize( 00063 const size_type rows 00064 ,const size_type cols 00065 ) 00066 { 00067 namespace rcp = MemMngPack; 00068 namespace rmp = MemMngPack; 00069 typedef Teuchos::RCP<DMatrix> vec_ptr_t; 00070 vec_ptr_t gms_ptr = Teuchos::rcp(new DMatrix(rows,cols)); 00071 this->initialize( 00072 (*gms_ptr)() 00073 ,BLAS_Cpp::no_trans 00074 ,Teuchos::rcp( 00075 new rmp::ReleaseResource_ref_count_ptr<DMatrix>( 00076 gms_ptr 00077 ) 00078 ) 00079 ); 00080 } 00081 00082 void MultiVectorMutableDense::initialize( 00083 DMatrixSlice gms 00084 ,BLAS_Cpp::Transp gms_trans 00085 ,const release_resource_ptr_t& gms_release 00086 ) 00087 { 00088 gms_.bind(gms); 00089 gms_trans_ = gms_trans; 00090 gms_release_ = gms_release; 00091 } 00092 00093 // Overridden from MatrixOpGetGMS 00094 00095 const DMatrixSlice MultiVectorMutableDense::get_gms_view() const 00096 { 00097 if(gms_trans_ == BLAS_Cpp::trans) { 00098 TEST_FOR_EXCEPT(true); // ToDo: We need to create a copy and transpose it! 00099 } 00100 return get_gms(); // No memory to allocate! 00101 } 00102 00103 void MultiVectorMutableDense::free_gms_view(const DMatrixSlice* gms_view) const 00104 { 00105 if(gms_trans_ == BLAS_Cpp::trans) { 00106 TEST_FOR_EXCEPT(true); // ToDo: We need to free the copy that we created in get_gms_view() 00107 } 00108 else { 00109 // Nothing to free! 00110 } 00111 } 00112 00113 // Overridden from MatrixOpGetGMSMutable 00114 00115 DMatrixSlice MultiVectorMutableDense::get_gms_view() 00116 { 00117 if(gms_trans_ == BLAS_Cpp::trans) { 00118 TEST_FOR_EXCEPT(true); // ToDo: We need to create a copy and transpose it! 00119 } 00120 return set_gms(); // No memory to allocate! 00121 } 00122 00123 void MultiVectorMutableDense::commit_gms_view(DMatrixSlice* gms_view) 00124 { 00125 if(gms_trans_ == BLAS_Cpp::trans) { 00126 TEST_FOR_EXCEPT(true); // ToDo: We need to free the copy that we created in get_gms_view() 00127 } 00128 else { 00129 // Nothing to free! 00130 } 00131 } 00132 00133 // Overridden from MultiVector 00134 00135 MultiVectorMutableDense::access_by_t 00136 MultiVectorMutableDense::access_by() const 00137 { 00138 return ROW_ACCESS | COL_ACCESS | DIAG_ACCESS; // row, column and diagonal access is available! 00139 } 00140 00141 // Overridden from MultiVectorMutable 00142 00143 MultiVectorMutableDense::vec_mut_ptr_t 00144 MultiVectorMutableDense::col(index_type j) 00145 { 00146 namespace rcp = MemMngPack; 00147 return Teuchos::rcp( 00148 new VectorMutableDense( 00149 DenseLinAlgPack::col( set_gms(), gms_trans(), j ) 00150 ,Teuchos::null ) ); 00151 } 00152 00153 MultiVectorMutableDense::vec_mut_ptr_t 00154 MultiVectorMutableDense::row(index_type i) 00155 { 00156 namespace rcp = MemMngPack; 00157 return Teuchos::rcp( 00158 new VectorMutableDense( 00159 DenseLinAlgPack::row( set_gms(), gms_trans(), i ) 00160 ,Teuchos::null ) ); 00161 } 00162 00163 MultiVectorMutableDense::vec_mut_ptr_t 00164 MultiVectorMutableDense::diag(int k) 00165 { 00166 namespace rcp = MemMngPack; 00167 return Teuchos::rcp( 00168 new VectorMutableDense( 00169 gms_.diag( gms_trans() == BLAS_Cpp::no_trans ? k : -k ) 00170 ,Teuchos::null ) ); 00171 } 00172 00173 MultiVectorMutableDense::multi_vec_mut_ptr_t 00174 MultiVectorMutableDense::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng) 00175 { 00176 namespace rcp = MemMngPack; 00177 return Teuchos::rcp( 00178 new MultiVectorMutableDense( 00179 gms_( 00180 gms_trans() == BLAS_Cpp::no_trans ? row_rng : col_rng 00181 ,gms_trans() == BLAS_Cpp::no_trans ? col_rng : row_rng ) 00182 ,gms_trans() 00183 ,Teuchos::null ) ); 00184 } 00185 00186 // Overridden from MatrixBase 00187 00188 size_type MultiVectorMutableDense::rows() const 00189 { 00190 return BLAS_Cpp::rows( get_gms().rows(), get_gms().cols(), gms_trans() ); 00191 } 00192 00193 size_type MultiVectorMutableDense::cols() const 00194 { 00195 return BLAS_Cpp::cols( get_gms().rows(), get_gms().cols(), gms_trans() ); 00196 } 00197 00198 // Overridden from MatrixOp 00199 00200 void MultiVectorMutableDense::zero_out() 00201 { 00202 gms_ = 0.0; 00203 } 00204 00205 void MultiVectorMutableDense::Mt_S( value_type alpha ) 00206 { 00207 DenseLinAlgPack::Mt_S(&gms_,alpha); 00208 } 00209 00210 MatrixOp& MultiVectorMutableDense::operator=(const MatrixOp& mwo_rhs) 00211 { 00212 DenseLinAlgPack::assign( &set_gms(), MatrixDenseEncap(mwo_rhs)(), gms_trans() ); 00213 return *this; 00214 } 00215 00216 std::ostream& MultiVectorMutableDense::output(std::ostream& out) const 00217 { 00218 if(gms_trans() == BLAS_Cpp::no_trans) 00219 return out << gms_; 00220 return MatrixOpSerial::output(out); 00221 } 00222 00223 bool MultiVectorMutableDense::Mp_StM( 00224 MatrixOp* mwo_lhs, value_type alpha 00225 ,BLAS_Cpp::Transp trans_rhs 00226 ) const 00227 { 00228 return MultiVectorMutable::Mp_StM(mwo_lhs,alpha,trans_rhs); 00229 } 00230 00231 bool MultiVectorMutableDense::Mp_StM( 00232 value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs 00233 ) 00234 { 00235 return MultiVectorMutable::Mp_StM(alpha,M_rhs,trans_rhs); 00236 } 00237 00238 bool MultiVectorMutableDense::syrk( 00239 BLAS_Cpp::Transp M_trans, value_type alpha 00240 ,value_type beta, MatrixSymOp* sym_lhs 00241 ) const 00242 { 00243 #ifdef TEUCHOS_DEBUG 00244 TEST_FOR_EXCEPTION( 00245 sym_lhs == NULL, std::invalid_argument 00246 ,"MultiVectorMutableDense::syrk(...) : Error!" ); 00247 #endif 00248 MatrixSymOpGetGMSSymMutable 00249 *sym_get_lhs = dynamic_cast<MatrixSymOpGetGMSSymMutable*>(sym_lhs); 00250 if(!sym_get_lhs) 00251 return false; 00252 MatrixDenseSymMutableEncap sym_gms_lhs(sym_get_lhs); 00253 DenseLinAlgPack::syrk( M_trans, alpha, get_gms(), beta, &sym_gms_lhs() ); 00254 return true; 00255 } 00256 00257 bool MultiVectorMutableDense::Mp_StMtM( 00258 MatrixOp* mwo_lhs, value_type alpha 00259 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00260 ,BLAS_Cpp::Transp trans_rhs2 00261 ,value_type beta ) const 00262 { 00263 if(MultiVector::Mp_StMtM(mwo_lhs,alpha,mwo_rhs1,trans_rhs1,trans_rhs2,beta)) 00264 return true; 00265 return MatrixOpSerial::Mp_StMtM(mwo_lhs,alpha,mwo_rhs1,trans_rhs1,trans_rhs2,beta); 00266 } 00267 00268 bool MultiVectorMutableDense::Mp_StMtM( 00269 MatrixOp* mwo_lhs, value_type alpha 00270 ,BLAS_Cpp::Transp trans_rhs1 00271 ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2 00272 ,value_type beta ) const 00273 { 00274 if(MultiVector::Mp_StMtM(mwo_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2,beta)) 00275 return true; 00276 return MatrixOpSerial::Mp_StMtM(mwo_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2,beta); 00277 } 00278 00279 // Overridden from MatrixOpSerial 00280 00281 void MultiVectorMutableDense::Vp_StMtV( 00282 DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00283 , const DVectorSlice& vs_rhs2, value_type beta) const 00284 { 00285 DenseLinAlgPack::Vp_StMtV( 00286 vs_lhs,alpha,gms_,BLAS_Cpp::trans_trans(gms_trans(),trans_rhs1),vs_rhs2,beta); 00287 } 00288 00289 void MultiVectorMutableDense::Vp_StMtV( 00290 DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00291 , const SpVectorSlice& sv_rhs2, value_type beta) const 00292 { 00293 AbstractLinAlgPack::Vp_StMtV( 00294 vs_lhs,alpha,gms_,BLAS_Cpp::trans_trans(gms_trans(),trans_rhs1),sv_rhs2,beta); 00295 } 00296 00297 // protected 00298 00299 // Overridden from MultiVector 00300 00301 void MultiVectorMutableDense::apply_op( 00302 EApplyBy apply_by, const RTOpPack::RTOp& primary_op 00303 ,const size_t num_multi_vecs, const MultiVector** multi_vecs 00304 ,const size_t num_targ_multi_vecs, MultiVectorMutable** targ_multi_vecs 00305 ,RTOpPack::ReductTarget* reduct_objs[] 00306 ,const index_type primary_first_ele , const index_type primary_sub_dim , const index_type primary_global_offset 00307 ,const index_type secondary_first_ele , const index_type secondary_sub_dim 00308 ) const 00309 { 00310 MultiVector::apply_op( 00311 apply_by, primary_op, num_multi_vecs, multi_vecs, num_targ_multi_vecs, targ_multi_vecs 00312 ,reduct_objs 00313 ,primary_first_ele, primary_sub_dim, primary_global_offset, secondary_first_ele, secondary_sub_dim 00314 ); // ToDo: Provide Specialized implementation if needed? 00315 } 00316 00317 void MultiVectorMutableDense::apply_op( 00318 EApplyBy apply_by, const RTOpPack::RTOp& primary_op, const RTOpPack::RTOp& secondary_op 00319 ,const size_t num_multi_vecs, const MultiVector** multi_vecs 00320 ,const size_t num_targ_multi_vecs, MultiVectorMutable** targ_multi_vecs 00321 ,RTOpPack::ReductTarget *reduct_obj 00322 ,const index_type primary_first_ele , const index_type primary_sub_dim , const index_type primary_global_offset 00323 ,const index_type secondary_first_ele , const index_type secondary_sub_dim 00324 ) const 00325 { 00326 MultiVector::apply_op( 00327 apply_by, primary_op, secondary_op, num_multi_vecs, multi_vecs, num_targ_multi_vecs, targ_multi_vecs 00328 ,reduct_obj 00329 ,primary_first_ele, primary_sub_dim, primary_global_offset, secondary_first_ele, secondary_sub_dim 00330 ); // ToDo: Provide Specialized implementation if needed? 00331 } 00332 00333 } // end namespace AbstractLinAlgPack
1.7.4