|
Anasazi
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Anasazi: Block Eigensolvers Package 00005 // Copyright (2010) 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef __TSQR_Trilinos_Randomizer_hpp 00030 #define __TSQR_Trilinos_Randomizer_hpp 00031 00032 #include "AnasaziConfigDefs.hpp" 00033 #include "TsqrTypeAdaptor.hpp" 00034 #include "TsqrCommFactory.hpp" 00035 00036 #include "Tsqr_ScalarTraits.hpp" 00037 #include "Tsqr_Random_GlobalMatrix.hpp" 00038 00039 #include <string> 00040 00043 00044 namespace TSQR { 00045 namespace Trilinos { 00057 template< class S, class LO, class GO, class MV, class Gen > 00058 class Randomizer { 00059 public: 00060 typedef S scalar_type; 00061 typedef LO local_ordinal_type; 00062 typedef GO global_ordinal_type; 00063 typedef MV multivector_type; 00064 typedef Gen normalgen_type; 00065 typedef Teuchos::RCP< Gen > normalgen_ptr; 00066 typedef TSQR::Random::MatrixGenerator< S, LO, Gen > matgen_type; 00067 00068 typedef typename TSQR::ScalarTraits< S >::magnitude_type magnitude_type; 00069 00070 typedef TsqrTypeAdaptor< S, LO, GO, MV > type_adaptor; 00071 typedef typename type_adaptor::comm_type comm_type; 00072 typedef typename type_adaptor::comm_ptr comm_ptr; 00073 typedef Teuchos::RCP< MessengerBase< LO > > ordinal_messenger_ptr; 00074 typedef Teuchos::RCP< MessengerBase< S > > scalar_messenger_ptr; 00075 00076 virtual ~Randomizer() {} 00077 00087 virtual void 00088 randomMultiVector (multivector_type& A, 00089 const magnitude_type singularValues[]) 00090 { 00091 using TSQR::Random::randomGlobalMatrix; 00092 using Teuchos::ArrayRCP; 00093 typedef MatView< local_ordinal_type, scalar_type > matview_type; 00094 00095 local_ordinal_type nrowsLocal, ncols, LDA; 00096 fetchDims (A, nrowsLocal, ncols, LDA); 00097 ArrayRCP< scalar_type > A_ptr = fetchNonConstView (A); 00098 matview_type A_view (nrowsLocal, ncols, A_ptr.get(), LDA); 00099 00100 randomGlobalMatrix (pGen_.get(), A_view, singularValues, 00101 pOrdinalMessenger_.get(), pScalarMessenger_.get()); 00102 } 00103 00104 protected: 00113 void 00114 init (const multivector_type& mv, 00115 const normalgen_ptr& pGen) 00116 { 00117 pGen_ = pGen; 00118 // This is done in a multivector type - dependent way. 00119 fetchMessengers (mv, pScalarMessenger_, pOrdinalMessenger_); 00120 } 00121 00122 private: 00138 virtual void 00139 fetchDims (const multivector_type& A, 00140 local_ordinal_type& nrowsLocal, 00141 local_ordinal_type& ncols, 00142 local_ordinal_type& LDA) const = 0; 00143 00151 virtual Teuchos::ArrayRCP< scalar_type > 00152 fetchNonConstView (multivector_type& A) const = 0; 00153 00156 virtual void 00157 fetchMessengers (const multivector_type& mv, 00158 scalar_messenger_ptr& pScalarMessenger, 00159 ordinal_messenger_ptr& pOrdinalMessenger) const = 0; 00160 00161 normalgen_ptr pGen_; 00162 ordinal_messenger_ptr pOrdinalMessenger_; 00163 scalar_messenger_ptr pScalarMessenger_; 00164 }; 00165 00166 } // namespace Trilinos 00167 } // namespace TSQR 00168 00169 #endif // __TSQR_Trilinos_Randomizer_hpp
1.7.6.1