|
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 #ifndef MATRIX_SPARSE_COOR_SERIAL_H 00030 #define MATRIX_SPARSE_COOR_SERIAL_H 00031 00032 #include "AbstractLinAlgPack_MatrixOp.hpp" 00033 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp" 00034 #include "AbstractLinAlgPack_MatrixLoadSparseElements.hpp" 00035 #include "AbstractLinAlgPack_MatrixExtractSparseElements.hpp" 00036 #include "ReleaseResource.hpp" 00037 00038 namespace AbstractLinAlgPack { 00039 00044 class MatrixSparseCOORSerial 00045 : virtual public AbstractLinAlgPack::MatrixOp 00046 , virtual public MatrixLoadSparseElements 00047 , virtual public MatrixExtractSparseElements 00048 { 00049 public: 00050 00053 00055 typedef Teuchos::RCP< 00056 MemMngPack::ReleaseResource> release_resource_ptr_t; 00061 class ReleaseValRowColArrays 00062 : public MemMngPack::ReleaseResource 00063 { 00064 public: 00066 ReleaseValRowColArrays( 00067 value_type *val 00068 ,index_type *row_i 00069 ,index_type *col_j 00070 ) 00071 :val_(val) 00072 ,row_i_(row_i) 00073 ,col_j_(col_j) 00074 ,owns_mem_(true) 00075 {} 00076 // Calls delete on buffers if <tt>this->owns_memory() == true</tt> 00077 ~ReleaseValRowColArrays(); 00079 bool resource_is_bound() const; 00081 void release_ownership() { owns_mem_ = false; } 00082 value_type* val() { return val_; } 00083 index_type* row_i() { return row_i_; } 00084 index_type* col_j() { return col_j_; } 00085 private: 00086 value_type *val_; 00087 index_type *row_i_; 00088 index_type *col_j_; 00089 bool owns_mem_; 00090 // not defined and not to be called 00091 ReleaseValRowColArrays(); 00092 ReleaseValRowColArrays(const ReleaseValRowColArrays&); 00093 ReleaseValRowColArrays& operator=(const ReleaseValRowColArrays&); 00094 }; // end class ReleaseValRowColArrays 00095 00097 00100 00103 MatrixSparseCOORSerial(); 00104 00155 void set_buffers( 00156 size_type max_nz 00157 ,value_type *val 00158 ,index_type *row_i 00159 ,index_type *col_j 00160 ,const release_resource_ptr_t &release_resource 00161 ,size_type rows = 0 00162 ,size_type cols = 0 00163 ,size_type nz = 0 00164 ,bool check_input = false 00165 ); 00166 00175 void set_uninitialized(); 00176 00178 00181 00183 value_type* val(); 00185 const value_type* val() const; 00187 index_type* row_i(); 00189 const index_type* row_i() const; 00191 index_type* col_j(); 00193 const index_type* col_j() const; 00195 const release_resource_ptr_t& release_resource() const; 00196 00198 00201 00203 size_type rows() const; 00205 size_type cols() const; 00207 size_type nz() const; 00208 00210 00213 00215 const VectorSpace& space_cols() const; 00217 const VectorSpace& space_rows() const; 00219 MatrixOp& operator=(const MatrixOp& M); 00221 std::ostream& output(std::ostream& out) const; 00223 void Vp_StMtV( 00224 VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00225 , const Vector& v_rhs2, value_type beta) const; 00226 00227 // ToDo: Add more method overrides as they are needed! 00228 00230 00233 00235 void reinitialize( 00236 size_type rows 00237 ,size_type cols 00238 ,size_type max_nz 00239 ,EAssumeElementUniqueness element_uniqueness 00240 ); 00241 void reset_to_load_values(); 00243 void get_load_nonzeros_buffers( 00244 size_type max_nz_load 00245 ,value_type **val 00246 ,index_type **row_i 00247 ,index_type **col_j 00248 ); 00250 void commit_load_nonzeros_buffers( 00251 size_type nz_commit 00252 ,value_type **val 00253 ,index_type **row_i 00254 ,index_type **col_j 00255 ); 00257 void finish_construction( bool test_setup ); 00258 00260 00263 00265 index_type count_nonzeros( 00266 EElementUniqueness element_uniqueness 00267 ,const index_type inv_row_perm[] 00268 ,const index_type inv_col_perm[] 00269 ,const Range1D &row_rng 00270 ,const Range1D &col_rng 00271 ,index_type dl 00272 ,index_type du 00273 ) const; 00275 void coor_extract_nonzeros( 00276 EElementUniqueness element_uniqueness 00277 ,const index_type inv_row_perm[] 00278 ,const index_type inv_col_perm[] 00279 ,const Range1D &row_rng 00280 ,const Range1D &col_rng 00281 ,index_type dl 00282 ,index_type du 00283 ,value_type alpha 00284 ,const index_type len_Aval 00285 ,value_type Aval[] 00286 ,const index_type len_Aij 00287 ,index_type Arow[] 00288 ,index_type Acol[] 00289 ,const index_type row_offset 00290 ,const index_type col_offset 00291 ) const; 00292 00294 00295 private: 00296 00297 // ////////////////////////////// 00298 // Private types 00299 00300 // ////////////////////////////// 00301 // Public types 00302 00303 size_type rows_; 00304 size_type cols_; 00305 size_type max_nz_; 00306 EAssumeElementUniqueness element_uniqueness_; 00307 size_type nz_; 00308 value_type *val_; 00309 index_type *row_i_; 00310 index_type *col_j_; 00311 release_resource_ptr_t release_resource_; 00312 00313 bool self_allocate_; // True if this allocates the memory 00314 00315 VectorSpaceSerial space_cols_; 00316 VectorSpaceSerial space_rows_; 00317 00318 size_type max_nz_load_; // cashed 00319 bool reload_val_only_; // cashed 00320 size_type reload_val_only_nz_last_; // cashed 00321 00322 // ////////////////////////////// 00323 // Private member functions 00324 00325 void make_storage_unique(); 00326 00327 // static 00328 static release_resource_ptr_t release_resource_null_; 00329 00330 }; // end class MatrixSparseCOORSerial 00331 00332 // ////////////////////////////////// 00333 // Inline members 00334 00335 inline 00336 value_type* MatrixSparseCOORSerial::val() 00337 { 00338 make_storage_unique(); 00339 return val_; 00340 } 00341 00342 inline 00343 const value_type* MatrixSparseCOORSerial::val() const 00344 { 00345 return val_; 00346 } 00347 00348 inline 00349 index_type* MatrixSparseCOORSerial::row_i() 00350 { 00351 make_storage_unique(); 00352 return row_i_; 00353 } 00354 00355 inline 00356 const index_type* MatrixSparseCOORSerial::row_i() const 00357 { 00358 return row_i_; 00359 } 00360 00361 inline 00362 index_type* MatrixSparseCOORSerial::col_j() 00363 { 00364 make_storage_unique(); 00365 return col_j_; 00366 } 00367 00368 inline 00369 const index_type* MatrixSparseCOORSerial::col_j() const 00370 { 00371 return col_j_; 00372 } 00373 00374 inline 00375 const MatrixSparseCOORSerial::release_resource_ptr_t& 00376 MatrixSparseCOORSerial::release_resource() const 00377 { 00378 return self_allocate_ ? release_resource_null_ : release_resource_; 00379 } 00380 00381 } // end namespace AbstractLinAlgPack 00382 00383 #endif // MATRIX_SPARSE_COOR_SERIAL_H 00384
1.7.4