Anasazi Version of the Day
Tsqr_CombineBenchmark.hpp
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., 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 #ifndef __TSQR_Test_CombineBenchmark_hpp
00030 #define __TSQR_Test_CombineBenchmark_hpp
00031 
00032 #include <Tsqr_Config.hpp>
00033 #include <Tsqr_CombineBenchmarker.hpp>
00034 
00035 #include <Tsqr_CombineDefault.hpp>
00036 #include <Tsqr_CombineNative.hpp>
00037 #ifdef HAVE_TSQR_FORTRAN
00038 #  include <Tsqr_CombineFortran.hpp>
00039 #endif // HAVE_TSQR_FORTRAN
00040 
00041 #include <algorithm>
00042 #include <iostream>
00043 #include <limits>
00044 #include <sstream>
00045 #include <stdexcept>
00046 #include <utility>
00047 #include <vector>
00048 
00051 
00052 namespace TSQR {
00053   namespace Test {
00054 
00055     template< class CombineType, class TimerType >
00056     static void
00057     benchmarkCombineType (std::ostream& out,
00058         std::vector<int>& iseed,
00059         const std::string& dataTypeName,
00060         const std::string& combineTypeName,
00061         const typename CombineType::ordinal_type numRows,
00062         const typename CombineType::ordinal_type numCols,
00063         const int numTrials)
00064     {
00065       using TSQR::Random::NormalGenerator;
00066       using std::complex;
00067       using std::endl;
00068       using std::pair;
00069       using std::string;
00070       using std::vector;
00071 
00072       typedef typename CombineType::ordinal_type ordinal_type;
00073       typedef typename CombineType::scalar_type scalar_type;
00074       typedef typename CombineType::magnitude_type magnitude_type;
00075       typedef CombineBenchmarker< ordinal_type, scalar_type, CombineType, TimerType > benchmarker_type;
00076       typedef pair< double, double > results_type;
00077 
00078       // FIXME These two should have different seeds!!!
00079       NormalGenerator< ordinal_type, scalar_type > normGen (iseed);
00080       NormalGenerator< ordinal_type, magnitude_type > normMagGen (iseed);
00081 
00082       benchmarker_type benchmarker (normGen, normMagGen, numTrials);
00083       results_type results (benchmarker.R1R2_benchmark (numCols),
00084           benchmarker.RA_benchmark (numRows, numCols));
00085       out << combineTypeName 
00086     << "," << dataTypeName
00087     << "," << "R1_R2"
00088     << "," << numRows
00089     << "," << numCols
00090     << "," << numTrials
00091     << "," << results.first
00092     << endl;
00093       out << combineTypeName 
00094     << "," << dataTypeName
00095     << "," << "R_A"
00096     << "," << numRows
00097     << "," << numCols
00098     << "," << numTrials
00099     << "," << results.second
00100     << endl;
00101     }
00102 
00103     template< class Scalar, class TimerType >
00104     static void
00105     benchmarkAllCombineTypes (std::ostream& out,
00106             std::vector<int>& iseed,
00107             const std::string& dataTypeName,
00108             const int numRows,
00109             const int numCols,
00110             const int numTrials)
00111     {
00112       using std::string;
00113 
00114       {
00115   typedef CombineNative< int, Scalar > combine_type;
00116   string combineTypeName ("Native");
00117   benchmarkCombineType< combine_type, TimerType > (out, iseed, dataTypeName, combineTypeName, numRows, numCols, numTrials);
00118       }
00119 #ifdef HAVE_TSQR_FORTRAN
00120       {
00121   typedef CombineFortran< Scalar > combine_type;
00122   string combineTypeName ("Fortran");
00123   benchmarkCombineType< combine_type, TimerType > (out, iseed, dataTypeName, combineTypeName, numRows, numCols, numTrials);
00124       }
00125 #endif // HAVE_TSQR_FORTRAN
00126       {
00127   typedef CombineDefault< int, Scalar > combine_type;
00128   string combineTypeName ("Default");
00129   benchmarkCombineType< combine_type, TimerType > (out, iseed, dataTypeName, combineTypeName, numRows, numCols, numTrials);
00130       }
00131     }
00132 
00133 
00134     template< class TimerType >
00135     static void
00136     benchmarkAllCombineTypesAndScalars (std::ostream& out,
00137           std::vector<int>& iseed,
00138           const int numRows,
00139           const int numCols,
00140           const int numTrials,
00141           const bool testComplex)
00142     {
00143       using std::complex;
00144       using std::string;
00145       string dataTypeName;
00146 
00147       dataTypeName = "float";
00148       benchmarkAllCombineTypes< float, TimerType > (out, iseed, dataTypeName, numRows, numCols, numTrials);
00149       dataTypeName = "double";
00150       benchmarkAllCombineTypes< double, TimerType > (out, iseed, dataTypeName, numRows, numCols, numTrials);
00151 
00152       if (testComplex)
00153   {
00154 #ifdef HAVE_TSQR_COMPLEX
00155     dataTypeName = "complex<float>";
00156     benchmarkAllCombineTypes< complex<float>, TimerType > (out, iseed, dataTypeName, 
00157                  numRows, numCols, numTrials);
00158     dataTypeName = "complex<double>";
00159     benchmarkAllCombineTypes< complex<double>, TimerType > (out, iseed, dataTypeName, 
00160                   numRows, numCols, numTrials);
00161 #else // Don't HAVE_TSQR_COMPLEX
00162     throw std::logic_error("TSQR not built with complex arithmetic support");
00163 #endif // HAVE_TSQR_COMPLEX
00164   }
00165     }         
00166 
00167 
00168     template< class TimerType >
00169     void
00170     benchmarkCombine (std::ostream& out,
00171           const int numRows,
00172           const int numCols,
00173           const int numTrials,
00174           std::vector<int>& seed,
00175           const bool useSeedValues,
00176           const bool testComplex)
00177     {
00178       if (! useSeedValues)
00179   {
00180     seed.resize (4);
00181     seed[0] = 0;
00182     seed[1] = 0;
00183     seed[2] = 0;
00184     seed[3] = 1;
00185   }
00186       benchmarkAllCombineTypesAndScalars< TimerType > (out, seed, numRows, numCols, numTrials, testComplex);
00187     }
00188 
00189   } // namespace Test
00190 } // namespace TSQR
00191 
00192 #endif // __TSQR_Test_CombineBenchmark_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends