|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef MATRIX_SPARSE_COOR_SERIAL_H 00043 #define MATRIX_SPARSE_COOR_SERIAL_H 00044 00045 #include "AbstractLinAlgPack_MatrixOp.hpp" 00046 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp" 00047 #include "AbstractLinAlgPack_MatrixLoadSparseElements.hpp" 00048 #include "AbstractLinAlgPack_MatrixExtractSparseElements.hpp" 00049 #include "ReleaseResource.hpp" 00050 00051 namespace AbstractLinAlgPack { 00052 00057 class MatrixSparseCOORSerial 00058 : virtual public AbstractLinAlgPack::MatrixOp 00059 , virtual public MatrixLoadSparseElements 00060 , virtual public MatrixExtractSparseElements 00061 { 00062 public: 00063 00066 00068 typedef Teuchos::RCP< 00069 MemMngPack::ReleaseResource> release_resource_ptr_t; 00074 class ReleaseValRowColArrays 00075 : public MemMngPack::ReleaseResource 00076 { 00077 public: 00079 ReleaseValRowColArrays( 00080 value_type *val 00081 ,index_type *row_i 00082 ,index_type *col_j 00083 ) 00084 :val_(val) 00085 ,row_i_(row_i) 00086 ,col_j_(col_j) 00087 ,owns_mem_(true) 00088 {} 00089 // Calls delete on buffers if <tt>this->owns_memory() == true</tt> 00090 ~ReleaseValRowColArrays(); 00092 bool resource_is_bound() const; 00094 void release_ownership() { owns_mem_ = false; } 00095 value_type* val() { return val_; } 00096 index_type* row_i() { return row_i_; } 00097 index_type* col_j() { return col_j_; } 00098 private: 00099 value_type *val_; 00100 index_type *row_i_; 00101 index_type *col_j_; 00102 bool owns_mem_; 00103 // not defined and not to be called 00104 ReleaseValRowColArrays(); 00105 ReleaseValRowColArrays(const ReleaseValRowColArrays&); 00106 ReleaseValRowColArrays& operator=(const ReleaseValRowColArrays&); 00107 }; // end class ReleaseValRowColArrays 00108 00110 00113 00116 MatrixSparseCOORSerial(); 00117 00168 void set_buffers( 00169 size_type max_nz 00170 ,value_type *val 00171 ,index_type *row_i 00172 ,index_type *col_j 00173 ,const release_resource_ptr_t &release_resource 00174 ,size_type rows = 0 00175 ,size_type cols = 0 00176 ,size_type nz = 0 00177 ,bool check_input = false 00178 ); 00179 00188 void set_uninitialized(); 00189 00191 00194 00196 value_type* val(); 00198 const value_type* val() const; 00200 index_type* row_i(); 00202 const index_type* row_i() const; 00204 index_type* col_j(); 00206 const index_type* col_j() const; 00208 const release_resource_ptr_t& release_resource() const; 00209 00211 00214 00216 size_type rows() const; 00218 size_type cols() const; 00220 size_type nz() const; 00221 00223 00226 00228 const VectorSpace& space_cols() const; 00230 const VectorSpace& space_rows() const; 00232 MatrixOp& operator=(const MatrixOp& M); 00234 std::ostream& output(std::ostream& out) const; 00236 void Vp_StMtV( 00237 VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00238 , const Vector& v_rhs2, value_type beta) const; 00239 00240 // ToDo: Add more method overrides as they are needed! 00241 00243 00246 00248 void reinitialize( 00249 size_type rows 00250 ,size_type cols 00251 ,size_type max_nz 00252 ,EAssumeElementUniqueness element_uniqueness 00253 ); 00254 void reset_to_load_values(); 00256 void get_load_nonzeros_buffers( 00257 size_type max_nz_load 00258 ,value_type **val 00259 ,index_type **row_i 00260 ,index_type **col_j 00261 ); 00263 void commit_load_nonzeros_buffers( 00264 size_type nz_commit 00265 ,value_type **val 00266 ,index_type **row_i 00267 ,index_type **col_j 00268 ); 00270 void finish_construction( bool test_setup ); 00271 00273 00276 00278 index_type count_nonzeros( 00279 EElementUniqueness element_uniqueness 00280 ,const index_type inv_row_perm[] 00281 ,const index_type inv_col_perm[] 00282 ,const Range1D &row_rng 00283 ,const Range1D &col_rng 00284 ,index_type dl 00285 ,index_type du 00286 ) const; 00288 void coor_extract_nonzeros( 00289 EElementUniqueness element_uniqueness 00290 ,const index_type inv_row_perm[] 00291 ,const index_type inv_col_perm[] 00292 ,const Range1D &row_rng 00293 ,const Range1D &col_rng 00294 ,index_type dl 00295 ,index_type du 00296 ,value_type alpha 00297 ,const index_type len_Aval 00298 ,value_type Aval[] 00299 ,const index_type len_Aij 00300 ,index_type Arow[] 00301 ,index_type Acol[] 00302 ,const index_type row_offset 00303 ,const index_type col_offset 00304 ) const; 00305 00307 00308 private: 00309 00310 // ////////////////////////////// 00311 // Private types 00312 00313 // ////////////////////////////// 00314 // Public types 00315 00316 size_type rows_; 00317 size_type cols_; 00318 size_type max_nz_; 00319 EAssumeElementUniqueness element_uniqueness_; 00320 size_type nz_; 00321 value_type *val_; 00322 index_type *row_i_; 00323 index_type *col_j_; 00324 release_resource_ptr_t release_resource_; 00325 00326 bool self_allocate_; // True if this allocates the memory 00327 00328 VectorSpaceSerial space_cols_; 00329 VectorSpaceSerial space_rows_; 00330 00331 size_type max_nz_load_; // cashed 00332 bool reload_val_only_; // cashed 00333 size_type reload_val_only_nz_last_; // cashed 00334 00335 // ////////////////////////////// 00336 // Private member functions 00337 00338 void make_storage_unique(); 00339 00340 // static 00341 static release_resource_ptr_t release_resource_null_; 00342 00343 }; // end class MatrixSparseCOORSerial 00344 00345 // ////////////////////////////////// 00346 // Inline members 00347 00348 inline 00349 value_type* MatrixSparseCOORSerial::val() 00350 { 00351 make_storage_unique(); 00352 return val_; 00353 } 00354 00355 inline 00356 const value_type* MatrixSparseCOORSerial::val() const 00357 { 00358 return val_; 00359 } 00360 00361 inline 00362 index_type* MatrixSparseCOORSerial::row_i() 00363 { 00364 make_storage_unique(); 00365 return row_i_; 00366 } 00367 00368 inline 00369 const index_type* MatrixSparseCOORSerial::row_i() const 00370 { 00371 return row_i_; 00372 } 00373 00374 inline 00375 index_type* MatrixSparseCOORSerial::col_j() 00376 { 00377 make_storage_unique(); 00378 return col_j_; 00379 } 00380 00381 inline 00382 const index_type* MatrixSparseCOORSerial::col_j() const 00383 { 00384 return col_j_; 00385 } 00386 00387 inline 00388 const MatrixSparseCOORSerial::release_resource_ptr_t& 00389 MatrixSparseCOORSerial::release_resource() const 00390 { 00391 return self_allocate_ ? release_resource_null_ : release_resource_; 00392 } 00393 00394 } // end namespace AbstractLinAlgPack 00395 00396 #endif // MATRIX_SPARSE_COOR_SERIAL_H 00397
1.7.6.1