|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00005 // Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include "Thyra_DefaultSpmdVectorSpace.hpp" 00030 #include "Thyra_DefaultProductVectorSpace.hpp" 00031 #include "Thyra_VectorStdOpsTester.hpp" 00032 #include "Thyra_MultiVectorStdOpsTester.hpp" 00033 #include "Thyra_TestingTools.hpp" 00034 #include "Teuchos_GlobalMPISession.hpp" 00035 #include "Teuchos_CommandLineProcessor.hpp" 00036 #include "Teuchos_VerboseObject.hpp" 00037 #include "Teuchos_DefaultComm.hpp" 00038 00039 namespace Thyra { 00040 00043 template <class Scalar> 00044 bool run_std_ops_tests( 00045 const int n 00046 ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType max_rel_err 00047 ,const bool dumpAll 00048 ,Teuchos::FancyOStream *out_arg 00049 ) 00050 { 00051 00052 using Teuchos::RCP; 00053 using Teuchos::rcp; 00054 using Teuchos::OSTab; 00055 typedef Teuchos::ScalarTraits<Scalar> ST; 00056 typedef typename ST::magnitudeType ScalarMag; 00057 typedef Thyra::Ordinal Index; 00058 00059 RCP<Teuchos::FancyOStream> 00060 out = rcp(new Teuchos::FancyOStream(rcp(out_arg,false))); 00061 00062 VectorStdOpsTester<Scalar> vectorStdOpsTester; 00063 vectorStdOpsTester.warning_tol(ScalarMag(0.1)*max_rel_err); 00064 vectorStdOpsTester.error_tol(max_rel_err); 00065 MultiVectorStdOpsTester<Scalar> multiVectorStdOpsTester; 00066 multiVectorStdOpsTester.warning_tol(ScalarMag(0.1)*max_rel_err); 00067 multiVectorStdOpsTester.error_tol(max_rel_err); 00068 00069 if(out.get()) *out << "\n*** Entering run_std_ops_tests<"<<ST::name()<<">(...) ...\n"; 00070 00071 bool success = true; 00072 00073 if(out.get()) *out << "\nCreating a serial vector space svs with n="<<n<<" vector elements ...\n"; 00074 00075 const RCP<const Teuchos::Comm<Ordinal> > 00076 comm = Teuchos::DefaultComm<Ordinal>::getComm(); 00077 00078 const RCP<Thyra::VectorSpaceBase<Scalar> > svs = 00079 Thyra::defaultSpmdVectorSpace<Scalar>(comm,n,-1); 00080 00081 if(out.get()) *out << "\nTesting standard vector ops with svs ...\n"; 00082 if(!vectorStdOpsTester.checkStdOps(*svs, OSTab(out).get(), dumpAll)) success = false; 00083 00084 if(out.get()) *out << "\nTesting standard multi-vector ops with svs ...\n"; 00085 if(!multiVectorStdOpsTester.checkStdOps(*svs, OSTab(out).get(), dumpAll)) success = false; 00086 00087 const int numBlocks = 3; 00088 00089 if(out.get()) *out << "\nCreating a product space pvs with numBlocks="<<numBlocks<<" and n="<<n<<"vector elements per block ...\n"; 00090 00091 Teuchos::Array<Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > > 00092 vecSpaces(numBlocks); 00093 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > 00094 spaceBlock = Thyra::defaultSpmdVectorSpace<Scalar>(comm,n,-1); 00095 for( int i = 0; i < numBlocks; ++i ) 00096 vecSpaces[i] = spaceBlock; 00097 00098 RCP<Thyra::DefaultProductVectorSpace<Scalar> > pvs = 00099 rcp(new Thyra::DefaultProductVectorSpace<Scalar>(numBlocks,&vecSpaces[0])); 00100 00101 if(out.get()) *out << "\nTesting standard vector ops with pvs ...\n"; 00102 if(!vectorStdOpsTester.checkStdOps(*pvs, OSTab(out).get(), dumpAll)) success = false; 00103 00104 if(out.get()) *out << "\nTesting standard multi-vector ops with pvs ...\n"; 00105 if(!multiVectorStdOpsTester.checkStdOps(*pvs, OSTab(out).get(), dumpAll)) success = false; 00106 00107 if(out.get()) *out << "\nCreating a nested product space ppvs with numBlocks="<<numBlocks<<" product spaces as components ...\n"; 00108 00109 Teuchos::Array<Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > > 00110 blockVecSpaces(numBlocks); 00111 for( int i = 0; i < numBlocks; ++i ) 00112 blockVecSpaces[i] = pvs; 00113 00114 RCP<Thyra::DefaultProductVectorSpace<Scalar> > ppvs = 00115 rcp(new Thyra::DefaultProductVectorSpace<Scalar>(numBlocks, &blockVecSpaces[0])); 00116 00117 if(out.get()) *out << "\nTesting standard vector ops with ppvs ...\n"; 00118 if(!vectorStdOpsTester.checkStdOps(*ppvs, OSTab(out).get(), dumpAll)) success = false; 00119 00120 if(out.get()) *out << "\nTesting standard multi-vector ops with ppvs ...\n"; 00121 if(!multiVectorStdOpsTester.checkStdOps(*ppvs, OSTab(out).get(), dumpAll)) success = false; 00122 00123 return success; 00124 00125 } 00126 00127 } // namespace Thyra 00128 00129 int main( int argc, char* argv[] ) { 00130 00131 using Teuchos::CommandLineProcessor; 00132 00133 bool success = true; 00134 bool verbose = true; 00135 bool dumpAll = false; 00136 00137 Teuchos::GlobalMPISession mpiSession(&argc,&argv); 00138 // KL 27 Jul 2006 -- Commenting out unused variables 00139 // const int procRank = Teuchos::GlobalMPISession::getRank(); 00140 // const int numProc = Teuchos::GlobalMPISession::getNProc(); 00141 00142 Teuchos::RCP<Teuchos::FancyOStream> 00143 out = Teuchos::VerboseObjectBase::getDefaultOStream(); 00144 00145 try { 00146 00147 // 00148 // Read options from the command-line 00149 // 00150 00151 00152 CommandLineProcessor clp; 00153 clp.throwExceptions(false); 00154 clp.addOutputSetupOptions(true); 00155 00156 int local_dim = 4; 00157 clp.setOption( "local-dim", &local_dim, "Number of vector elements per process." ); 00158 00159 double eps_scale = 200.0; 00160 clp.setOption( "eps-scale", &eps_scale, "Constant (greater than 1) to scale eps by in error tests." ); 00161 00162 clp.setOption( "verbose", "quiet", &verbose, 00163 "Determines if any output is printed or not." ); 00164 00165 clp.setOption( "dump-all", "no-dump", &dumpAll, "Determines if quantities are dumped or not." ); 00166 00167 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv); 00168 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return; 00169 00170 // 00171 // Run the tests 00172 // 00173 00174 #if defined(HAVE_THYRA_FLOAT) 00175 if( !Thyra::run_std_ops_tests<float>(local_dim,float(eps_scale*Teuchos::ScalarTraits<float>::eps()),dumpAll,verbose?&*out:NULL) ) success = false; 00176 #endif 00177 if( !Thyra::run_std_ops_tests<double>(local_dim,double(eps_scale*Teuchos::ScalarTraits<double>::eps()),dumpAll,verbose?&*out:NULL) ) success = false; 00178 #if defined(HAVE_THYRA_COMPLEX) && defined(HAVE_THYRA_FLOAT) 00179 if( !Thyra::run_std_ops_tests<std::complex<float> >(local_dim,float(eps_scale*Teuchos::ScalarTraits<float>::eps()),dumpAll,verbose?&*out:NULL) ) success = false; 00180 #endif 00181 #if defined(HAVE_THYRA_COMPLEX) 00182 if( !Thyra::run_std_ops_tests<std::complex<double> >(local_dim,double(eps_scale*Teuchos::ScalarTraits<double>::eps()),dumpAll,verbose?&*out:NULL) ) success = false; 00183 #endif 00184 #ifdef HAVE_TEUCHOS_GNU_MP 00185 //if( !Thyra::run_std_ops_tests<mpf_class>(local_dim,mpf_class(max_rel_err),dumpAll,verbose?&*out:NULL) ) success = false; 00186 // RAB: 4/16/2005: We can not instantiate the above since rmax() is not supported by this types ScalarTraits class 00187 // and it is needed by the class RTOpPack::ROpMaxIndexLessThanBound. This can be fixed using a template 00188 // conditional but I have not done this yet. 00189 #endif 00190 00191 } // end try 00192 catch( const std::exception &excpt ) { 00193 if(verbose) 00194 std::cerr << "*** Caught a standard exception : " << excpt.what() << std::endl; 00195 success = false; 00196 } 00197 catch( ... ) { 00198 if(verbose) 00199 std::cerr << "*** Caught an unknown exception!\n"; 00200 success = false; 00201 } 00202 00203 if(verbose) { 00204 if(success) 00205 *out << "\nAll of the tests seem to have run successfully!\n"; 00206 else 00207 *out << "\nOh no! at least one of the test failed!\n"; 00208 } 00209 00210 return success ? 0 : 1; 00211 00212 }
1.7.4