1 //===================================================== 2 // File : portable_perf_analyzer.hh 3 // Author : L. Plagne <laurent.plagne@edf.fr)> 4 // Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 5 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 6 //===================================================== 7 // 8 // This program is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU General Public License 10 // as published by the Free Software Foundation; either version 2 11 // of the License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, write to the Free Software 19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 // 21 #ifndef _PORTABLE_PERF_ANALYZER_HH 22 #define _PORTABLE_PERF_ANALYZER_HH 23 24 #include "utilities.h" 25 #include "timers/portable_timer.hh" 26 27 template <class Action> 28 class Portable_Perf_Analyzer{ 29 public: Portable_Perf_Analyzer()30 Portable_Perf_Analyzer( ):_nb_calc(0), m_time_action(0), _chronos(){ 31 MESSAGE("Portable_Perf_Analyzer Ctor"); 32 }; Portable_Perf_Analyzer(const Portable_Perf_Analyzer &)33 Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ 34 INFOS("Copy Ctor not implemented"); 35 exit(0); 36 }; ~Portable_Perf_Analyzer()37 ~Portable_Perf_Analyzer(){ 38 MESSAGE("Portable_Perf_Analyzer Dtor"); 39 }; 40 eval_mflops(int size)41 BTL_DONT_INLINE double eval_mflops(int size) 42 { 43 Action action(size); 44 45 // action.initialize(); 46 // time_action = time_calculate(action); 47 while (m_time_action < MIN_TIME) 48 { 49 if(_nb_calc==0) _nb_calc = 1; 50 else _nb_calc *= 2; 51 action.initialize(); 52 m_time_action = time_calculate(action); 53 } 54 55 // optimize 56 for (int i=1; i<BtlConfig::Instance.tries; ++i) 57 { 58 Action _action(size); 59 std::cout << " " << _action.nb_op_base()*_nb_calc/(m_time_action*1e6) << " "; 60 _action.initialize(); 61 m_time_action = std::min(m_time_action, time_calculate(_action)); 62 } 63 64 double time_action = m_time_action / (double(_nb_calc)); 65 66 // check 67 if (BtlConfig::Instance.checkResults && size<128) 68 { 69 action.initialize(); 70 action.calculate(); 71 action.check_result(); 72 } 73 return action.nb_op_base()/(time_action*1e6); 74 } 75 time_calculate(Action & action)76 BTL_DONT_INLINE double time_calculate(Action & action) 77 { 78 // time measurement 79 action.calculate(); 80 _chronos.start(); 81 for (unsigned int ii=0;ii<_nb_calc;ii++) 82 { 83 action.calculate(); 84 } 85 _chronos.stop(); 86 return _chronos.user_time(); 87 } 88 get_nb_calc()89 unsigned long long get_nb_calc() 90 { 91 return _nb_calc; 92 } 93 94 95 private: 96 unsigned long long _nb_calc; 97 double m_time_action; 98 Portable_Timer _chronos; 99 100 }; 101 102 #endif //_PORTABLE_PERF_ANALYZER_HH 103 104