portable_perf_analyzer.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  portable_perf_analyzer.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>
00004 // Copyright (C) EDF R&D,  mar d�c 3 18:59:35 CET 2002
00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //=====================================================
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 //
00021 #ifndef _PORTABLE_PERF_ANALYZER_HH
00022 #define _PORTABLE_PERF_ANALYZER_HH
00023 
00024 #include "utilities.h"
00025 #include "timers/portable_timer.hh"
00026 
00027 template <class Action>
00028 class Portable_Perf_Analyzer{
00029 public:
00030   Portable_Perf_Analyzer( ):_nb_calc(0), m_time_action(0), _chronos(){
00031     MESSAGE("Portable_Perf_Analyzer Ctor");
00032   };
00033   Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){
00034     INFOS("Copy Ctor not implemented");
00035     exit(0);
00036   };
00037   ~Portable_Perf_Analyzer(){
00038     MESSAGE("Portable_Perf_Analyzer Dtor");
00039   };
00040 
00041   BTL_DONT_INLINE double eval_mflops(int size)
00042   {
00043     Action action(size);
00044 
00045 //     action.initialize();
00046 //     time_action = time_calculate(action);
00047     while (m_time_action < MIN_TIME)
00048     {
00049       if(_nb_calc==0) _nb_calc = 1;
00050       else            _nb_calc *= 2;
00051       action.initialize();
00052       m_time_action = time_calculate(action);
00053     }
00054 
00055     // optimize
00056     for (int i=1; i<BtlConfig::Instance.tries; ++i)
00057     {
00058       Action _action(size);
00059       std::cout << " " << _action.nb_op_base()*_nb_calc/(m_time_action*1e6) << " ";
00060       _action.initialize();
00061       m_time_action = std::min(m_time_action, time_calculate(_action));
00062     }
00063 
00064     double time_action = m_time_action / (double(_nb_calc));
00065 
00066     // check
00067     if (BtlConfig::Instance.checkResults && size<128)
00068     {
00069       action.initialize();
00070       action.calculate();
00071       action.check_result();
00072     }
00073     return action.nb_op_base()/(time_action*1e6);
00074   }
00075 
00076   BTL_DONT_INLINE double time_calculate(Action & action)
00077   {
00078     // time measurement
00079     action.calculate();
00080     _chronos.start();
00081     for (int ii=0;ii<_nb_calc;ii++)
00082     {
00083       action.calculate();
00084     }
00085     _chronos.stop();
00086     return _chronos.user_time();
00087   }
00088 
00089   unsigned long long get_nb_calc()
00090   {
00091     return _nb_calc;
00092   }
00093 
00094 
00095 private:
00096   unsigned long long _nb_calc;
00097   double m_time_action;
00098   Portable_Timer _chronos;
00099 
00100 };
00101 
00102 #endif //_PORTABLE_PERF_ANALYZER_HH
00103 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:09