AbstractLinAlgPack_COOMatrixWithPartitionedViewSubclass.cpp

Go to the documentation of this file.
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_COOMatrixWithPartitionedViewSubclass.hpp"
00032 #include "AbstractLinAlgPack_SparseVectorSliceOp.hpp"
00033 #include "AbstractLinAlgPack_SparseElement.hpp"
00034 #include "AbstractLinAlgPack_COOMPartitionOp.hpp"
00035 #include "AbstractLinAlgPack_COOMPartitionOut.hpp"
00036 #include "AbstractLinAlgPack_COOMatrixTmplConvertToSparseCompressedColumn.hpp"
00037 #include "DenseLinAlgPack_DMatrixOp.hpp"
00038 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp"
00039 
00040 namespace LinAlgOpPack {
00041 
00042 using AbstractLinAlgPack::Vp_StV;
00043 using AbstractLinAlgPack::Vp_StMtV;
00044 using AbstractLinAlgPack::Mp_StM;
00045 using AbstractLinAlgPack::Mp_StMtM;
00046 
00047 } // end namespace LinAlgOpPack
00048 
00049 namespace AbstractLinAlgPack {
00050 
00051 size_type COOMatrixWithPartitionedViewSubclass::nz() const
00052 {
00053   return m().coom_view().nz();
00054 }
00055 
00056 std::ostream& COOMatrixWithPartitionedViewSubclass::output(std::ostream& out) const {
00057   return out << m().coom_view()();
00058 }
00059 
00060 // Level-1 BLAS
00061 
00062 void COOMatrixWithPartitionedViewSubclass::Mp_StM(DMatrixSlice* gms_lhs, value_type alpha
00063   , BLAS_Cpp::Transp trans_rhs) const
00064 {
00065   AbstractLinAlgPack::Mp_StM(gms_lhs,alpha,m().coom_view()(),trans_rhs);
00066 }
00067 
00068 // Level-2 BLAS
00069 
00070 void COOMatrixWithPartitionedViewSubclass::Vp_StMtV(DVectorSlice* vs_lhs, value_type alpha
00071   , BLAS_Cpp::Transp trans_rhs1, const DVectorSlice& vs_rhs2, value_type beta) const
00072 {
00073   AbstractLinAlgPack::Vp_StMtV(vs_lhs, alpha, m().coom_view()(), trans_rhs1, vs_rhs2, beta);
00074 }
00075 
00076 void COOMatrixWithPartitionedViewSubclass::Vp_StMtV(DVectorSlice* vs_lhs, value_type alpha
00077   , BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2, value_type beta) const
00078 {
00079   DVector v_rhs2;
00080   LinAlgOpPack::assign(&v_rhs2,sv_rhs2);
00081   AbstractLinAlgPack::Vp_StMtV(vs_lhs, alpha, m().coom_view()(), trans_rhs1, v_rhs2(), beta);
00082 }
00083 
00084 value_type COOMatrixWithPartitionedViewSubclass::transVtMtV(const DVectorSlice& vs_rhs1
00085   , BLAS_Cpp::Transp trans_rhs2, const DVectorSlice& vs_rhs3) const
00086 {
00087   DVector tmp;
00088   LinAlgOpPack::V_MtV(&tmp,m().coom_view()(),trans_rhs2,vs_rhs3);
00089   return DenseLinAlgPack::dot(vs_rhs1,tmp());
00090 }
00091 
00092 value_type COOMatrixWithPartitionedViewSubclass::transVtMtV(const SpVectorSlice& sv_rhs1
00093   , BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3) const
00094 {
00095   DVector v_rhs3;
00096   LinAlgOpPack::assign(&v_rhs3,sv_rhs3);
00097   DVector tmp;
00098   LinAlgOpPack::V_MtV(&tmp,m().coom_view()(),trans_rhs2,v_rhs3());
00099   return dot(sv_rhs1,tmp());
00100 }
00101 
00102 // Level-3 BLAS
00103 
00104 void COOMatrixWithPartitionedViewSubclass::Mp_StMtM(DMatrixSlice* gms_lhs, value_type alpha
00105   , BLAS_Cpp::Transp trans_rhs1, const DMatrixSlice& gms_rhs2
00106   , BLAS_Cpp::Transp trans_rhs2, value_type beta) const
00107 {
00108   AbstractLinAlgPack::Mp_StMtM(gms_lhs, alpha, m().coom_view()(), trans_rhs1, gms_rhs2, trans_rhs2, beta);
00109 }
00110 
00111 void COOMatrixWithPartitionedViewSubclass::Mp_StMtM(DMatrixSlice* gms_lhs, value_type alpha, const DMatrixSlice& gms_rhs1
00112   , BLAS_Cpp::Transp trans_rhs1, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
00113 {
00114   AbstractLinAlgPack::Mp_StMtM(gms_lhs, alpha, gms_rhs1, trans_rhs1, m().coom_view()(), trans_rhs2, beta);
00115 }
00116 
00117 // Overridden from ConvertToCSC
00118 
00119 size_type COOMatrixWithPartitionedViewSubclass::num_in_column(
00120     BLAS_Cpp::Transp          trans
00121   , size_type             col_offset
00122   , const IVector::value_type*    col_perm
00123   , size_type*            num_in_col  ) const
00124 {
00125   return COOM_num_in_column( m().coom_view()(), trans, col_offset
00126     , col_perm, num_in_col );
00127 }
00128   
00129 void COOMatrixWithPartitionedViewSubclass::insert_nonzeros(
00130     BLAS_Cpp::Transp          trans
00131   , value_type            alpha
00132   , size_type             row_offset
00133   , size_type             col_offset
00134   , const IVector::value_type*    row_perm
00135   , const IVector::value_type*    col_perm
00136   , size_type*            next_nz_in_col
00137   , FortranTypes::f_dbl_prec*     D_val
00138   , FortranTypes::f_int*        D_row_i     ) const
00139 {
00140   COOM_insert_nonzeros( m().coom_view()(), trans, alpha, row_offset, col_offset, row_perm
00141       , col_perm, next_nz_in_col, D_val, D_row_i );
00142 }
00143 
00144 value_type COOMatrixWithPartitionedViewSubclass::insert_scaled_nonzeros(
00145     BLAS_Cpp::Transp          trans
00146   , value_type            scaled_max_ele
00147   , size_type             row_offset
00148   , size_type             col_offset
00149   , const IVector::value_type*    row_perm
00150   , const IVector::value_type*    col_perm
00151   , size_type*            next_nz_in_col
00152   , FortranTypes::f_dbl_prec*     D_val
00153   , FortranTypes::f_int*        D_row_i     ) const
00154 {
00155   return COOM_insert_scaled_nonzeros( m().coom_view()(), trans, scaled_max_ele, row_offset
00156       , col_offset, row_perm, col_perm, next_nz_in_col, D_val, D_row_i );
00157 }
00158 
00159   // Overridden from MatrixConvertToSparseFortranCompatible
00160 
00161 FortranTypes::f_int
00162 COOMatrixWithPartitionedViewSubclass::num_nonzeros( EExtractRegion extract_region ) const
00163 {
00164   // ToDo: Implement upper and lower triangular regions when needed!
00165   TEST_FOR_EXCEPT( !(  extract_region == EXTRACT_FULL_MATRIX  ) );
00166 
00167   return this->nz();  
00168 }
00169 
00170 void COOMatrixWithPartitionedViewSubclass::coor_extract_nonzeros(
00171     EExtractRegion extract_region
00172   , const FortranTypes::f_int len_Aval
00173     , FortranTypes::f_dbl_prec Aval[]
00174   , const FortranTypes::f_int len_Aij
00175     , FortranTypes::f_int Arow[]
00176     , FortranTypes::f_int Acol[]
00177     , const FortranTypes::f_int row_offset
00178     , const FortranTypes::f_int col_offset
00179    ) const
00180 {
00181   // ToDo: Implement upper and lower triangular regions when needed!
00182   TEST_FOR_EXCEPT( !(  extract_region == EXTRACT_FULL_MATRIX  ) );
00183 
00184 
00185   // Get the permuted view (Partition<> object)
00186   typedef COOMatrixWithPartitionedView::partitioned_view_type::partition_type
00187     part_view_t;
00188   const part_view_t
00189     part_view = m().coom_view()();
00190 
00191   const FortranTypes::f_int
00192     nz = part_view.nz();
00193 
00194   // Validate the input
00195   TEST_FOR_EXCEPT( !(  len_Aval == 0 || (len_Aval == nz && Aval)       ) );
00196   TEST_FOR_EXCEPT( !(  len_Aij  == 0 || (len_Aij  == nz && Arow && Acol)   ) );
00197   
00198   // Get overall row and column offsets
00199   const part_view_t::difference_type
00200     r_off = part_view.row_offset() + row_offset,
00201     c_off = part_view.col_offset() + col_offset;
00202 
00203   // Fill the nonzeros and structure.
00204   part_view_t::const_iterator
00205     itr   = part_view.begin();
00206   FortranTypes::f_dbl_prec
00207     *l_Aval = Aval;
00208   FortranTypes::f_int
00209     *l_Arow = Arow,
00210     *l_Acol = Acol;
00211   for( ; itr != part_view.end(); ++itr ) {
00212     if( len_Aval )
00213       *l_Aval++ = itr->value();
00214     if( len_Aij ) {
00215       *l_Arow++ = itr->row_i() + r_off;
00216       *l_Acol++ = itr->col_j() + c_off;
00217     }
00218   }
00219 }
00220 
00221 } // end namespace AbstractLinAlgPack

Generated on Tue Oct 20 12:51:42 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7