00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 #include "Teuchos_arrayArg.hpp"
00039
00040 namespace Thyra {
00041
00044 template <class Scalar>
00045 bool run_std_ops_tests(
00046 const int n
00047 ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType max_rel_err
00048 ,const bool dumpAll
00049 ,Teuchos::FancyOStream *out_arg
00050 )
00051 {
00052
00053 using Teuchos::RefCountPtr;
00054 using Teuchos::rcp;
00055 using Teuchos::OSTab;
00056 typedef Teuchos::ScalarTraits<Scalar> ST;
00057 typedef typename ST::magnitudeType ScalarMag;
00058 typedef Thyra::Index Index;
00059
00060 RefCountPtr<Teuchos::FancyOStream>
00061 out = rcp(new Teuchos::FancyOStream(rcp(out_arg,false)));
00062
00063 VectorStdOpsTester<Scalar> vectorStdOpsTester;
00064 vectorStdOpsTester.warning_tol(ScalarMag(0.1)*max_rel_err);
00065 vectorStdOpsTester.error_tol(max_rel_err);
00066 MultiVectorStdOpsTester<Scalar> multiVectorStdOpsTester;
00067 multiVectorStdOpsTester.warning_tol(ScalarMag(0.1)*max_rel_err);
00068 multiVectorStdOpsTester.error_tol(max_rel_err);
00069
00070 if(out.get()) *out << "\n*** Entering run_std_ops_tests<"<<ST::name()<<">(...) ...\n";
00071
00072 bool success = true;
00073
00074 if(out.get()) *out << "\nCreating a serial vector space svs with n="<<n<<" vector elements ...\n";
00075
00076 const RefCountPtr<const Teuchos::Comm<Index> >
00077 comm = Teuchos::DefaultComm<Index>::getComm();
00078 const DefaultSpmdVectorSpace<Scalar> svs(comm,n,-1);
00079
00080 if(out.get()) *out << "\nTesting standard vector ops with svs ...\n";
00081 if(!vectorStdOpsTester.checkStdOps(svs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00082
00083 if(out.get()) *out << "\nTesting standard multi-vector ops with svs ...\n";
00084 if(!multiVectorStdOpsTester.checkStdOps(svs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00085
00086 const int numBlocks = 3;
00087
00088 if(out.get()) *out << "\nCreating a product space pvs with numBlocks="<<numBlocks<<" and n="<<n<<"vector elements per block ...\n";
00089
00090 Teuchos::Array<Teuchos::RefCountPtr<const Thyra::VectorSpaceBase<Scalar> > >
00091 vecSpaces(numBlocks);
00092 Teuchos::RefCountPtr<const Thyra::VectorSpaceBase<Scalar> >
00093 spaceBlock = Teuchos::rcp(new Thyra::DefaultSpmdVectorSpace<Scalar>(comm,n,-1));
00094
00095 for( int i = 0; i < numBlocks; ++i )
00096 vecSpaces[i] = spaceBlock;
00097
00098 Thyra::DefaultProductVectorSpace<Scalar> pvs(numBlocks,&vecSpaces[0]);
00099
00100 if(out.get()) *out << "\nTesting standard vector ops with pvs ...\n";
00101 if(!vectorStdOpsTester.checkStdOps(pvs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00102
00103 if(out.get()) *out << "\nTesting standard multi-vector ops with pvs ...\n";
00104 if(!multiVectorStdOpsTester.checkStdOps(pvs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00105
00106 if(out.get()) *out << "\nCreating a nested product space ppvs with numBlocks="<<numBlocks<<" product spaces as components ...\n";
00107
00108 Teuchos::Array<Teuchos::RefCountPtr<const Thyra::VectorSpaceBase<Scalar> > >
00109 blockVecSpaces(numBlocks);
00110 for( int i = 0; i < numBlocks; ++i )
00111 blockVecSpaces[i] = Teuchos::rcp(&pvs,false);
00112
00113 Thyra::DefaultProductVectorSpace<Scalar> ppvs(numBlocks,&blockVecSpaces[0]);
00114
00115 if(out.get()) *out << "\nTesting standard vector ops with ppvs ...\n";
00116 if(!vectorStdOpsTester.checkStdOps(ppvs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00117
00118 if(out.get()) *out << "\nTesting standard multi-vector ops with ppvs ...\n";
00119 if(!multiVectorStdOpsTester.checkStdOps(ppvs,OSTab(out).getOStream().get(),dumpAll)) success = false;
00120
00121 return success;
00122
00123 }
00124
00125 }
00126
00127 int main( int argc, char* argv[] ) {
00128
00129 using Teuchos::CommandLineProcessor;
00130
00131 bool success = true;
00132 bool verbose = true;
00133 bool dumpAll = false;
00134
00135 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00136
00137
00138
00139
00140 Teuchos::RefCountPtr<Teuchos::FancyOStream>
00141 out = Teuchos::VerboseObjectBase::getDefaultOStream();
00142
00143 try {
00144
00145
00146
00147
00148
00149 int local_dim = 4;
00150 CommandLineProcessor clp;
00151 clp.throwExceptions(false);
00152 clp.addOutputSetupOptions(true);
00153 clp.setOption( "verbose", "quiet", &verbose, "Determines if any output is printed or not." );
00154 clp.setOption( "dump-all", "no-dump", &dumpAll, "Determines if quantities are dumped or not." );
00155 clp.setOption( "local-dim", &local_dim, "Number of vector elements per process." );
00156 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00157 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
00158
00159
00160
00161
00162
00163 if( !Thyra::run_std_ops_tests<float>(local_dim,float(100.0*Teuchos::ScalarTraits<float>::eps()),dumpAll,verbose?&*out:NULL) ) success = false;
00164 if( !Thyra::run_std_ops_tests<double>(local_dim,double(100.0*Teuchos::ScalarTraits<double>::eps()),dumpAll,verbose?&*out:NULL) ) success = false;
00165 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00166 if( !Thyra::run_std_ops_tests<std::complex<float> >(local_dim,float(100.0*Teuchos::ScalarTraits<float>::eps()),dumpAll,verbose?&*out:NULL) ) success = false;
00167 if( !Thyra::run_std_ops_tests<std::complex<double> >(local_dim,double(100.0*Teuchos::ScalarTraits<double>::eps()),dumpAll,verbose?&*out:NULL) ) success = false;
00168 #endif
00169 #ifdef HAVE_TEUCHOS_GNU_MP
00170
00171
00172
00173
00174 #endif
00175
00176 }
00177 catch( const std::exception &excpt ) {
00178 if(verbose)
00179 std::cerr << "*** Caught a standard exception : " << excpt.what() << std::endl;
00180 success = false;
00181 }
00182 catch( ... ) {
00183 if(verbose)
00184 std::cerr << "*** Caught an unknown exception!\n";
00185 success = false;
00186 }
00187
00188 if(verbose) {
00189 if(success)
00190 *out << "\nAll of the tests seem to have run successfully!\n";
00191 else
00192 *out << "\nOh no! at least one of the test failed!\n";
00193 }
00194
00195 return success ? 0 : 1;
00196
00197 }