Anasazi  Version of the Day
TsqrRandomizer.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright (2010) 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 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
29 #ifndef __TSQR_Trilinos_Randomizer_hpp
30 #define __TSQR_Trilinos_Randomizer_hpp
31 
32 #include "AnasaziConfigDefs.hpp"
33 #include "TsqrTypeAdaptor.hpp"
34 #include "TsqrCommFactory.hpp"
35 
36 #include "Tsqr_ScalarTraits.hpp"
37 #include "Tsqr_Random_GlobalMatrix.hpp"
38 
39 #include <string>
40 
43 
44 namespace TSQR {
45  namespace Trilinos {
57  template< class S, class LO, class GO, class MV, class Gen >
58  class Randomizer {
59  public:
60  typedef S scalar_type;
61  typedef LO local_ordinal_type;
62  typedef GO global_ordinal_type;
63  typedef MV multivector_type;
64  typedef Gen normalgen_type;
66  typedef TSQR::Random::MatrixGenerator< S, LO, Gen > matgen_type;
67 
68  typedef typename TSQR::ScalarTraits< S >::magnitude_type magnitude_type;
69 
70  typedef TsqrTypeAdaptor< S, LO, GO, MV > type_adaptor;
71  typedef typename type_adaptor::comm_type comm_type;
72  typedef typename type_adaptor::comm_ptr comm_ptr;
75 
76  virtual ~Randomizer() {}
77 
87  virtual void
88  randomMultiVector (multivector_type& A,
89  const magnitude_type singularValues[])
90  {
91  using TSQR::Random::randomGlobalMatrix;
92  using Teuchos::ArrayRCP;
93  typedef MatView< local_ordinal_type, scalar_type > matview_type;
94 
95  local_ordinal_type nrowsLocal, ncols, LDA;
96  fetchDims (A, nrowsLocal, ncols, LDA);
97  ArrayRCP< scalar_type > A_ptr = fetchNonConstView (A);
98  matview_type A_view (nrowsLocal, ncols, A_ptr.get(), LDA);
99 
100  randomGlobalMatrix (pGen_.get(), A_view, singularValues,
101  pOrdinalMessenger_.get(), pScalarMessenger_.get());
102  }
103 
104  protected:
113  void
114  init (const multivector_type& mv,
115  const normalgen_ptr& pGen)
116  {
117  pGen_ = pGen;
118  // This is done in a multivector type - dependent way.
119  fetchMessengers (mv, pScalarMessenger_, pOrdinalMessenger_);
120  }
121 
122  private:
138  virtual void
139  fetchDims (const multivector_type& A,
140  local_ordinal_type& nrowsLocal,
141  local_ordinal_type& ncols,
142  local_ordinal_type& LDA) const = 0;
143 
152  fetchNonConstView (multivector_type& A) const = 0;
153 
156  virtual void
157  fetchMessengers (const multivector_type& mv,
158  scalar_messenger_ptr& pScalarMessenger,
159  ordinal_messenger_ptr& pOrdinalMessenger) const = 0;
160 
161  normalgen_ptr pGen_;
162  ordinal_messenger_ptr pOrdinalMessenger_;
163  scalar_messenger_ptr pScalarMessenger_;
164  };
165 
166  } // namespace Trilinos
167 } // namespace TSQR
168 
169 #endif // __TSQR_Trilinos_Randomizer_hpp
Generates random test problems for TSQR.
T * get() const
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
virtual void randomMultiVector(multivector_type &A, const magnitude_type singularValues[])
Fill A with a (pseudo)random (distributed) matrix.
void init(const multivector_type &mv, const normalgen_ptr &pGen)