bench.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  bench.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>
00004 // Copyright (C) EDF R&D,  lun sep 30 14:23:16 CEST 2002
00005 //=====================================================
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 //
00020 #ifndef BENCH_HH
00021 #define BENCH_HH
00022 
00023 #include "btl.hh"
00024 #include "bench_parameter.hh"
00025 #include <iostream>
00026 #include "utilities.h"
00027 #include "size_lin_log.hh"
00028 #include "xy_file.hh"
00029 #include <vector>
00030 #include <string>
00031 #include "timers/portable_perf_analyzer.hh"
00032 // #include "timers/mixed_perf_analyzer.hh"
00033 // #include "timers/x86_perf_analyzer.hh"
00034 // #include "timers/STL_perf_analyzer.hh"
00035 #ifdef HAVE_MKL
00036 extern "C" void cblas_saxpy(const int, const float, const float*, const int, float *, const int);
00037 #endif
00038 using namespace std;
00039 
00040 template <template<class> class Perf_Analyzer, class Action>
00041 BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
00042 {
00043   if (BtlConfig::skipAction(Action::name()))
00044     return;
00045 
00046   string filename="bench_"+Action::name()+".dat";
00047 
00048   INFOS("starting " <<filename);
00049 
00050   // utilities
00051 
00052   std::vector<double> tab_mflops(nb_point);
00053   std::vector<int> tab_sizes(nb_point);
00054 
00055   // matrices and vector size calculations
00056   size_lin_log(nb_point,size_min,size_max,tab_sizes);
00057 
00058   std::vector<int> oldSizes;
00059   std::vector<double> oldFlops;
00060   bool hasOldResults = read_xy_file(filename, oldSizes, oldFlops, true);
00061   int oldi = oldSizes.size() - 1;
00062 
00063   // loop on matrix size
00064   Perf_Analyzer<Action> perf_action;
00065   for (int i=nb_point-1;i>=0;i--)
00066   {
00067     //INFOS("size=" <<tab_sizes[i]<<"   ("<<nb_point-i<<"/"<<nb_point<<")");
00068     std::cout << " " << "size = " << tab_sizes[i] << "  " << std::flush;
00069 
00070     BTL_DISABLE_SSE_EXCEPTIONS();
00071     #ifdef HAVE_MKL
00072     {
00073       float dummy;
00074       cblas_saxpy(1,0,&dummy,1,&dummy,1);
00075     }
00076     #endif
00077 
00078     tab_mflops[i] = perf_action.eval_mflops(tab_sizes[i]);
00079     std::cout << tab_mflops[i];
00080     
00081     if (hasOldResults)
00082     {
00083       while (oldi>=0 && oldSizes[oldi]>tab_sizes[i])
00084         --oldi;
00085       if (oldi>=0 && oldSizes[oldi]==tab_sizes[i])
00086       {
00087         if (oldFlops[oldi]<tab_mflops[i])
00088           std::cout << "\t > ";
00089         else
00090           std::cout << "\t < ";
00091         std::cout << oldFlops[oldi];
00092       }
00093       --oldi;
00094     }
00095     std::cout << " MFlops    (" << nb_point-i << "/" << nb_point << ")" << std::endl;
00096   }
00097 
00098   if (!BtlConfig::Instance.overwriteResults)
00099   {
00100     if (hasOldResults)
00101     {
00102       // merge the two data
00103       std::vector<int> newSizes;
00104       std::vector<double> newFlops;
00105       int i=0;
00106       int j=0;
00107       while (i<tab_sizes.size() && j<oldSizes.size())
00108       {
00109         if (tab_sizes[i] == oldSizes[j])
00110         {
00111           newSizes.push_back(tab_sizes[i]);
00112           newFlops.push_back(std::max(tab_mflops[i], oldFlops[j]));
00113           ++i;
00114           ++j;
00115         }
00116         else if (tab_sizes[i] < oldSizes[j])
00117         {
00118           newSizes.push_back(tab_sizes[i]);
00119           newFlops.push_back(tab_mflops[i]);
00120           ++i;
00121         }
00122         else
00123         {
00124           newSizes.push_back(oldSizes[j]);
00125           newFlops.push_back(oldFlops[j]);
00126           ++j;
00127         }
00128       }
00129       while (i<tab_sizes.size())
00130       {
00131         newSizes.push_back(tab_sizes[i]);
00132         newFlops.push_back(tab_mflops[i]);
00133         ++i;
00134       }
00135       while (j<oldSizes.size())
00136       {
00137         newSizes.push_back(oldSizes[j]);
00138         newFlops.push_back(oldFlops[j]);
00139         ++j;
00140       }
00141       tab_mflops = newFlops;
00142       tab_sizes = newSizes;
00143     }
00144   }
00145 
00146   // dump the result in a file  :
00147   dump_xy_file(tab_sizes,tab_mflops,filename);
00148 
00149 }
00150 
00151 // default Perf Analyzer
00152 
00153 template <class Action>
00154 BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point ){
00155 
00156   // if the rdtsc is not available :
00157   bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point);
00158   // if the rdtsc is available :
00159 //    bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point);
00160 
00161 
00162   // Only for small problem size. Otherwize it will be too long
00163 //   bench<X86_Perf_Analyzer,Action>(size_min,size_max,nb_point);
00164 //   bench<STL_Perf_Analyzer,Action>(size_min,size_max,nb_point);
00165 
00166 }
00167 
00168 #endif


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:30