MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_MultiVectorMutableDense.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <assert.h>
43 
51 #include "Teuchos_Workspace.hpp"
52 #include "Teuchos_Assert.hpp"
53 
54 namespace AbstractLinAlgPack {
55 
56 // Constructors / initializers
57 
59  const size_type rows
60  ,const size_type cols
61  )
62 {
63  this->initialize(rows,cols);
64 }
65 
67  DMatrixSlice gms
68  ,BLAS_Cpp::Transp gms_trans
69  ,const release_resource_ptr_t& gms_release
70  )
71 {
72  this->initialize(gms,gms_trans,gms_release);
73 }
74 
76  const size_type rows
77  ,const size_type cols
78  )
79 {
80  namespace rcp = MemMngPack;
81  namespace rmp = MemMngPack;
83  vec_ptr_t gms_ptr = Teuchos::rcp(new DMatrix(rows,cols));
84  this->initialize(
85  (*gms_ptr)()
87  ,Teuchos::rcp(
88  new rmp::ReleaseResource_ref_count_ptr<DMatrix>(
89  gms_ptr
90  )
91  )
92  );
93 }
94 
96  DMatrixSlice gms
97  ,BLAS_Cpp::Transp gms_trans
98  ,const release_resource_ptr_t& gms_release
99  )
100 {
101  gms_.bind(gms);
104 }
105 
106 // Overridden from MatrixOpGetGMS
107 
109 {
110  if(gms_trans_ == BLAS_Cpp::trans) {
111  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: We need to create a copy and transpose it!
112  }
113  return get_gms(); // No memory to allocate!
114 }
115 
117 {
118  if(gms_trans_ == BLAS_Cpp::trans) {
119  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: We need to free the copy that we created in get_gms_view()
120  }
121  else {
122  // Nothing to free!
123  }
124 }
125 
126 // Overridden from MatrixOpGetGMSMutable
127 
129 {
130  if(gms_trans_ == BLAS_Cpp::trans) {
131  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: We need to create a copy and transpose it!
132  }
133  return set_gms(); // No memory to allocate!
134 }
135 
137 {
138  if(gms_trans_ == BLAS_Cpp::trans) {
139  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: We need to free the copy that we created in get_gms_view()
140  }
141  else {
142  // Nothing to free!
143  }
144 }
145 
146 // Overridden from MultiVector
147 
150 {
151  return ROW_ACCESS | COL_ACCESS | DIAG_ACCESS; // row, column and diagonal access is available!
152 }
153 
154 // Overridden from MultiVectorMutable
155 
158 {
159  namespace rcp = MemMngPack;
160  return Teuchos::rcp(
161  new VectorMutableDense(
163  ,Teuchos::null ) );
164 }
165 
168 {
169  namespace rcp = MemMngPack;
170  return Teuchos::rcp(
171  new VectorMutableDense(
173  ,Teuchos::null ) );
174 }
175 
178 {
179  namespace rcp = MemMngPack;
180  return Teuchos::rcp(
181  new VectorMutableDense(
182  gms_.diag( gms_trans() == BLAS_Cpp::no_trans ? k : -k )
183  ,Teuchos::null ) );
184 }
185 
187 MultiVectorMutableDense::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng)
188 {
189  namespace rcp = MemMngPack;
190  return Teuchos::rcp(
192  gms_(
193  gms_trans() == BLAS_Cpp::no_trans ? row_rng : col_rng
194  ,gms_trans() == BLAS_Cpp::no_trans ? col_rng : row_rng )
195  ,gms_trans()
196  ,Teuchos::null ) );
197 }
198 
199 // Overridden from MatrixBase
200 
202 {
203  return BLAS_Cpp::rows( get_gms().rows(), get_gms().cols(), gms_trans() );
204 }
205 
207 {
208  return BLAS_Cpp::cols( get_gms().rows(), get_gms().cols(), gms_trans() );
209 }
210 
211 // Overridden from MatrixOp
212 
214 {
215  gms_ = 0.0;
216 }
217 
219 {
220  DenseLinAlgPack::Mt_S(&gms_,alpha);
221 }
222 
224 {
226  return *this;
227 }
228 
229 std::ostream& MultiVectorMutableDense::output(std::ostream& out) const
230 {
232  return out << gms_;
233  return MatrixOpSerial::output(out);
234 }
235 
237  MatrixOp* mwo_lhs, value_type alpha
238  ,BLAS_Cpp::Transp trans_rhs
239  ) const
240 {
241  return MultiVectorMutable::Mp_StM(mwo_lhs,alpha,trans_rhs);
242 }
243 
245  value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
246  )
247 {
248  return MultiVectorMutable::Mp_StM(alpha,M_rhs,trans_rhs);
249 }
250 
252  BLAS_Cpp::Transp M_trans, value_type alpha
253  ,value_type beta, MatrixSymOp* sym_lhs
254  ) const
255 {
256 #ifdef TEUCHOS_DEBUG
258  sym_lhs == NULL, std::invalid_argument
259  ,"MultiVectorMutableDense::syrk(...) : Error!" );
260 #endif
262  *sym_get_lhs = dynamic_cast<MatrixSymOpGetGMSSymMutable*>(sym_lhs);
263  if(!sym_get_lhs)
264  return false;
265  MatrixDenseSymMutableEncap sym_gms_lhs(sym_get_lhs);
266  DenseLinAlgPack::syrk( M_trans, alpha, get_gms(), beta, &sym_gms_lhs() );
267  return true;
268 }
269 
271  MatrixOp* mwo_lhs, value_type alpha
272  ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
273  ,BLAS_Cpp::Transp trans_rhs2
274  ,value_type beta ) const
275 {
276  if(MultiVector::Mp_StMtM(mwo_lhs,alpha,mwo_rhs1,trans_rhs1,trans_rhs2,beta))
277  return true;
278  return MatrixOpSerial::Mp_StMtM(mwo_lhs,alpha,mwo_rhs1,trans_rhs1,trans_rhs2,beta);
279 }
280 
282  MatrixOp* mwo_lhs, value_type alpha
283  ,BLAS_Cpp::Transp trans_rhs1
284  ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
285  ,value_type beta ) const
286 {
287  if(MultiVector::Mp_StMtM(mwo_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2,beta))
288  return true;
289  return MatrixOpSerial::Mp_StMtM(mwo_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2,beta);
290 }
291 
292 // Overridden from MatrixOpSerial
293 
295  DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
296  , const DVectorSlice& vs_rhs2, value_type beta) const
297 {
299  vs_lhs,alpha,gms_,BLAS_Cpp::trans_trans(gms_trans(),trans_rhs1),vs_rhs2,beta);
300 }
301 
303  DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
304  , const SpVectorSlice& sv_rhs2, value_type beta) const
305 {
307  vs_lhs,alpha,gms_,BLAS_Cpp::trans_trans(gms_trans(),trans_rhs1),sv_rhs2,beta);
308 }
309 
310 // protected
311 
312 // Overridden from MultiVector
313 
315  EApplyBy apply_by, const RTOpPack::RTOp& primary_op
316  ,const size_t num_multi_vecs, const MultiVector** multi_vecs
317  ,const size_t num_targ_multi_vecs, MultiVectorMutable** targ_multi_vecs
318  ,RTOpPack::ReductTarget* reduct_objs[]
319  ,const index_type primary_first_ele , const index_type primary_sub_dim , const index_type primary_global_offset
320  ,const index_type secondary_first_ele , const index_type secondary_sub_dim
321  ) const
322 {
324  apply_by, primary_op, num_multi_vecs, multi_vecs, num_targ_multi_vecs, targ_multi_vecs
325  ,reduct_objs
326  ,primary_first_ele, primary_sub_dim, primary_global_offset, secondary_first_ele, secondary_sub_dim
327  ); // ToDo: Provide Specialized implementation if needed?
328 }
329 
331  EApplyBy apply_by, const RTOpPack::RTOp& primary_op, const RTOpPack::RTOp& secondary_op
332  ,const size_t num_multi_vecs, const MultiVector** multi_vecs
333  ,const size_t num_targ_multi_vecs, MultiVectorMutable** targ_multi_vecs
334  ,RTOpPack::ReductTarget *reduct_obj
335  ,const index_type primary_first_ele , const index_type primary_sub_dim , const index_type primary_global_offset
336  ,const index_type secondary_first_ele , const index_type secondary_sub_dim
337  ) const
338 {
340  apply_by, primary_op, secondary_op, num_multi_vecs, multi_vecs, num_targ_multi_vecs, targ_multi_vecs
341  ,reduct_obj
342  ,primary_first_ele, primary_sub_dim, primary_global_offset, secondary_first_ele, secondary_sub_dim
343  ); // ToDo: Provide Specialized implementation if needed?
344 }
345 
346 } // end namespace AbstractLinAlgPack
void apply_op(EApplyBy apply_by, const RTOpPack::RTOp &primary_op, const size_t num_multi_vecs, const MultiVector **multi_vecs, const size_t num_targ_multi_vecs, MultiVectorMutable **targ_multi_vecs, RTOpPack::ReductTarget *reduct_objs[], const index_type primary_first_ele, const index_type primary_sub_dim, const index_type primary_global_offset, const index_type secondary_first_ele, const index_type secondary_sub_dim) const
DVector "Adaptor" subclass for DenseLinAlgPack::DVectorSlice or DenseLinAlgPack::DVector objects...
DVectorSlice row(DMatrixSlice &gms, BLAS_Cpp::Transp trans, size_type i)
void initialize(const size_type rows, const size_type cols)
Call this->initialize(v,v_release) with an allocated DenseLinAlgPack::DVector object.
void Vp_StMtV(DVectorSlice *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta) const
std::ostream & output(std::ostream &out) const
void assign(DMatrix *gm_lhs, value_type alpha)
gm_lhs = alpha (elementwise)
multi_vec_mut_ptr_t mv_sub_view(const Range1D &row_rng, const Range1D &col_rng)
bool Mp_StM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
BLAS_Cpp::Transp gms_trans() const
Return if underlying matrix is being viewed as the transpose or non-transposed.
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return rows of a possible transposed matrix.
Abstract interface that allows the extraction of a non-const DenseLinAlgPack::DMatrixSliceSym view of...
void syrk(BLAS_Cpp::Transp trans, value_type alpha, const DMatrixSlice &gms_rhs, value_type beta, DMatrixSliceSym *sym_lhs)
Transposed.
bool Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &mwo_rhs1, BLAS_Cpp::Transp trans_rhs1, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
Interface adding operations specific for a symmetric matrix {abstract}.
DMatrixSlice set_gms()
Return the non-const dense matrix.
bool Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &mwo_rhs1, BLAS_Cpp::Transp trans_rhs1, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
Provides a specialized implementation for mwo_rhs1 of type MatrixSymDiag.
Not transposed.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const DMatrixSlice get_gms() const
Return a const dense matrix.
. One-based subregion index range class.
RTOpT< RTOp_value_type > RTOp
Helper class type that simplifies the usage of the MatrixSymOpGetGMSSymMutable interface for clients...
void Mt_S(DMatrixSlice *gms_lhs, value_type alpha)
gms_lhs *= alpha (BLAS xSCAL)
std::ostream * out
bool Mp_StM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs) const
virtual void Mp_StMtM(DMatrixSlice *gms_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DMatrixSlice &gms_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
gms_lhs = alpha * op(M_rhs1) * op(gms_rhs2) + beta * gms_lhs (right) (xGEMM)
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
DVectorSlice col(DMatrixSlice &gms, BLAS_Cpp::Transp trans, size_type j)
Transp trans_trans(Transp _trans1, Transp _trans2)
Return the transpose of the transpose argument.
Helper class type that simplifies the usage of the MatrixOpGetGMS interface for clients.
Base class for all matrices that support basic matrix operations.
Interface for a collection of non-mutable vectors (multi-vector, matrix).
MultiVectorMutableDense(const size_type rows=0, const size_type cols=0)
Calls this->initialize(rows,cols).
Interface for a collection of mutable vectors (multi-vector, matrix).
DVectorSlice diag(difference_type k=0)
void Vp_StMtV(DVectorSlice *vs_lhs, value_type alpha, const DMatrixSlice &gms_rhs1, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta=1.0)
vs_lhs = alpha * op(gms_rhs1) * vs_rhs2 + beta * vs_lhs (BLAS xGEMV)
friend void apply_op(EApplyBy apply_by, const RTOpPack::RTOp &primary_op, const size_t num_multi_vecs, const MultiVector *multi_vecs[], const size_t num_targ_multi_vecs, MultiVectorMutable *targ_multi_vecs[], RTOpPack::ReductTarget *reduct_objs[], const index_type primary_first_ele, const index_type primary_sub_dim, const index_type primary_global_offset, const index_type secondary_first_ele, const index_type secondary_sub_dim)
bool syrk(BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs) const
Transp
TRANS.
DenseLinAlgPack::DMatrix DMatrix
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const release_resource_ptr_t & gms_release() const
Return a RCP<> pointer to the object that will release the associated resource.