Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TsqrRandomizer.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Anasazi: Block Eigensolvers Package
4 //
5 // Copyright 2004 NTESS and the Anasazi contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef __TSQR_Trilinos_Randomizer_hpp
11 #define __TSQR_Trilinos_Randomizer_hpp
12 
13 #include "AnasaziConfigDefs.hpp"
14 #include "TsqrTypeAdaptor.hpp"
15 #include "TsqrCommFactory.hpp"
16 
17 #include "Tsqr_ScalarTraits.hpp"
18 #include "Tsqr_Random_GlobalMatrix.hpp"
19 
20 #include <string>
21 
24 
25 namespace TSQR {
26  namespace Trilinos {
38  template< class S, class LO, class GO, class MV, class Gen >
39  class Randomizer {
40  public:
41  typedef S scalar_type;
42  typedef LO local_ordinal_type;
43  typedef GO global_ordinal_type;
44  typedef MV multivector_type;
45  typedef Gen normalgen_type;
47  typedef TSQR::Random::MatrixGenerator< S, LO, Gen > matgen_type;
48 
49  typedef typename TSQR::ScalarTraits< S >::magnitude_type magnitude_type;
50 
51  typedef TsqrTypeAdaptor< S, LO, GO, MV > type_adaptor;
52  typedef typename type_adaptor::comm_type comm_type;
53  typedef typename type_adaptor::comm_ptr comm_ptr;
56 
57  virtual ~Randomizer() {}
58 
68  virtual void
69  randomMultiVector (multivector_type& A,
70  const magnitude_type singularValues[])
71  {
72  using TSQR::Random::randomGlobalMatrix;
73  using Teuchos::ArrayRCP;
74  typedef MatView< local_ordinal_type, scalar_type > matview_type;
75 
76  local_ordinal_type nrowsLocal, ncols, LDA;
77  fetchDims (A, nrowsLocal, ncols, LDA);
78  ArrayRCP< scalar_type > A_ptr = fetchNonConstView (A);
79  matview_type A_view (nrowsLocal, ncols, A_ptr.get(), LDA);
80 
81  randomGlobalMatrix (pGen_.get(), A_view, singularValues,
82  pOrdinalMessenger_.get(), pScalarMessenger_.get());
83  }
84 
85  protected:
94  void
95  init (const multivector_type& mv,
96  const normalgen_ptr& pGen)
97  {
98  pGen_ = pGen;
99  // This is done in a multivector type - dependent way.
100  fetchMessengers (mv, pScalarMessenger_, pOrdinalMessenger_);
101  }
102 
103  private:
119  virtual void
120  fetchDims (const multivector_type& A,
121  local_ordinal_type& nrowsLocal,
122  local_ordinal_type& ncols,
123  local_ordinal_type& LDA) const = 0;
124 
133  fetchNonConstView (multivector_type& A) const = 0;
134 
137  virtual void
138  fetchMessengers (const multivector_type& mv,
139  scalar_messenger_ptr& pScalarMessenger,
140  ordinal_messenger_ptr& pOrdinalMessenger) const = 0;
141 
142  normalgen_ptr pGen_;
143  ordinal_messenger_ptr pOrdinalMessenger_;
144  scalar_messenger_ptr pScalarMessenger_;
145  };
146 
147  } // namespace Trilinos
148 } // namespace TSQR
149 
150 #endif // __TSQR_Trilinos_Randomizer_hpp
T * get() const
Generates random test problems for TSQR.
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)