1 //===================================================== 2 // File : mean.cxx 3 // Author : L. Plagne <laurent.plagne (at) edf.fr)> 4 // Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 5 //===================================================== 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 // 20 #include "utilities.h" 21 #include <vector> 22 #include <string> 23 #include <iostream> 24 #include <fstream> 25 #include "bench_parameter.hh" 26 #include "utils/xy_file.hh" 27 #include <set> 28 29 using namespace std; 30 31 double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max); 32 33 class Lib_Mean{ 34 35 public: 36 Lib_Mean( void ):_lib_name(),_mean_in_cache(),_mean_out_of_cache(){ 37 MESSAGE("Lib_mean Default Ctor"); 38 MESSAGE("!!! should not be used"); 39 exit(0); 40 } 41 Lib_Mean(const string & name, const double & mic, const double & moc):_lib_name(name),_mean_in_cache(mic),_mean_out_of_cache(moc){ 42 MESSAGE("Lib_mean Ctor"); 43 } 44 Lib_Mean(const Lib_Mean & lm):_lib_name(lm._lib_name),_mean_in_cache(lm._mean_in_cache),_mean_out_of_cache(lm._mean_out_of_cache){ 45 MESSAGE("Lib_mean Copy Ctor"); 46 } 47 ~Lib_Mean( void ){ 48 MESSAGE("Lib_mean Dtor"); 49 } 50 51 double _mean_in_cache; 52 double _mean_out_of_cache; 53 string _lib_name; 54 55 bool operator < ( const Lib_Mean &right) const 56 { 57 //return ( this->_mean_out_of_cache > right._mean_out_of_cache) ; 58 return ( this->_mean_in_cache > right._mean_in_cache) ; 59 } 60 61 }; 62 63 64 int main( int argc , char *argv[] ) 65 { 66 67 if (argc<6){ 68 INFOS("!!! Error ... usage : main what mic Mic moc Moc filename1 finename2..."); 69 exit(0); 70 } 71 INFOS(argc); 72 73 int min_in_cache=atoi(argv[2]); 74 int max_in_cache=atoi(argv[3]); 75 int min_out_of_cache=atoi(argv[4]); 76 int max_out_of_cache=atoi(argv[5]); 77 78 79 multiset<Lib_Mean> s_lib_mean ; 80 81 for (int i=6;i<argc;i++){ 82 83 string filename=argv[i]; 84 85 INFOS(filename); 86 87 double mic=0; 88 double moc=0; 89 90 { 91 92 vector<int> tab_sizes; 93 vector<double> tab_mflops; 94 95 read_xy_file(filename,tab_sizes,tab_mflops); 96 97 mic=mean_calc(tab_sizes,tab_mflops,min_in_cache,max_in_cache); 98 moc=mean_calc(tab_sizes,tab_mflops,min_out_of_cache,max_out_of_cache); 99 100 Lib_Mean cur_lib_mean(filename,mic,moc); 101 102 s_lib_mean.insert(cur_lib_mean); 103 104 } 105 106 } 107 108 109 cout << "<TABLE BORDER CELLPADDING=2>" << endl ; 110 cout << " <TR>" << endl ; 111 cout << " <TH ALIGN=CENTER> " << argv[1] << " </TH>" << endl ; 112 cout << " <TH ALIGN=CENTER> <a href=""#mean_marker""> in cache <BR> mean perf <BR> Mflops </a></TH>" << endl ; 113 cout << " <TH ALIGN=CENTER> in cache <BR> % best </TH>" << endl ; 114 cout << " <TH ALIGN=CENTER> <a href=""#mean_marker""> out of cache <BR> mean perf <BR> Mflops </a></TH>" << endl ; 115 cout << " <TH ALIGN=CENTER> out of cache <BR> % best </TH>" << endl ; 116 cout << " <TH ALIGN=CENTER> details </TH>" << endl ; 117 cout << " <TH ALIGN=CENTER> comments </TH>" << endl ; 118 cout << " </TR>" << endl ; 119 120 multiset<Lib_Mean>::iterator is = s_lib_mean.begin(); 121 Lib_Mean best(*is); 122 123 124 for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){ 125 126 cout << " <TR>" << endl ; 127 cout << " <TD> " << is->_lib_name << " </TD>" << endl ; 128 cout << " <TD> " << is->_mean_in_cache << " </TD>" << endl ; 129 cout << " <TD> " << 100*(is->_mean_in_cache/best._mean_in_cache) << " </TD>" << endl ; 130 cout << " <TD> " << is->_mean_out_of_cache << " </TD>" << endl ; 131 cout << " <TD> " << 100*(is->_mean_out_of_cache/best._mean_out_of_cache) << " </TD>" << endl ; 132 cout << " <TD> " << 133 "<a href=\"#"<<is->_lib_name<<"_"<<argv[1]<<"\">snippet</a>/" 134 "<a href=\"#"<<is->_lib_name<<"_flags\">flags</a> </TD>" << endl ; 135 cout << " <TD> " << 136 "<a href=\"#"<<is->_lib_name<<"_comments\">click here</a> </TD>" << endl ; 137 cout << " </TR>" << endl ; 138 139 } 140 141 cout << "</TABLE>" << endl ; 142 143 ofstream output_file ("../order_lib",ios::out) ; 144 145 for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){ 146 output_file << is->_lib_name << endl ; 147 } 148 149 output_file.close(); 150 151 } 152 153 double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max){ 154 155 int size=tab_sizes.size(); 156 int nb_sample=0; 157 double mean=0.0; 158 159 for (int i=0;i<size;i++){ 160 161 162 if ((tab_sizes[i]>=size_min)&&(tab_sizes[i]<=size_max)){ 163 164 nb_sample++; 165 mean+=tab_mflops[i]; 166 167 } 168 169 170 } 171 172 if (nb_sample==0){ 173 INFOS("no data for mean calculation"); 174 return 0.0; 175 } 176 177 return mean/nb_sample; 178 } 179 180 181 182 183