aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/btl/data/mean.cxx
blob: 3e1a82d227bf8ef3a24c692a8616ddf5e9447887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//=====================================================
// File   :  mean.cxx
// Author :  L. Plagne <laurent.plagne@edf.fr)>        
// Copyright (C) EDF R&D,  lun sep 30 14:23:15 CEST 2002
//=====================================================
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 
#include "utilities.h"
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "bench_parameter.hh"
#include "utils/xy_file.hh"
#include <set>

using namespace std;

double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max);

class Lib_Mean{

public:
  Lib_Mean( void ):_lib_name(),_mean_in_cache(),_mean_out_of_cache(){
    MESSAGE("Lib_mean Default Ctor");
    MESSAGE("!!! should not be used");
    exit(0);
  }
  Lib_Mean(const string & name, const double & mic, const double & moc):_lib_name(name),_mean_in_cache(mic),_mean_out_of_cache(moc){
    MESSAGE("Lib_mean Ctor");
  }
  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){
    MESSAGE("Lib_mean Copy Ctor");
  }
  ~Lib_Mean( void ){
    MESSAGE("Lib_mean Dtor");
  }
    
  double _mean_in_cache;
  double _mean_out_of_cache;
  string _lib_name;

  bool operator < ( const Lib_Mean &right) const 
  {
    //return ( this->_mean_out_of_cache > right._mean_out_of_cache) ;
    return ( this->_mean_in_cache > right._mean_in_cache) ;
  }

}; 


int main( int argc , char *argv[] )
{

  if (argc<6){
    INFOS("!!! Error ... usage : main what mic Mic moc Moc filename1 finename2...");
    exit(0);
  }
  INFOS(argc);

  int min_in_cache=atoi(argv[2]);
  int max_in_cache=atoi(argv[3]);
  int min_out_of_cache=atoi(argv[4]);
  int max_out_of_cache=atoi(argv[5]);


  multiset<Lib_Mean> s_lib_mean ;

  for (int i=6;i<argc;i++){
    
    string filename=argv[i];
    
    INFOS(filename);

    double mic=0;
    double moc=0;

    {
      
      vector<int> tab_sizes;
      vector<double> tab_mflops;

      read_xy_file(filename,tab_sizes,tab_mflops);

      mic=mean_calc(tab_sizes,tab_mflops,min_in_cache,max_in_cache);
      moc=mean_calc(tab_sizes,tab_mflops,min_out_of_cache,max_out_of_cache);

      Lib_Mean cur_lib_mean(filename,mic,moc);
      
      s_lib_mean.insert(cur_lib_mean);	

    }   
           
  }


  cout << "<TABLE BORDER CELLPADDING=2>" << endl ;
  cout << "  <TR>" << endl ;
  cout << "    <TH ALIGN=CENTER> " << argv[1] << " </TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> <a href=""#mean_marker""> in cache <BR> mean perf <BR> Mflops </a></TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> in cache <BR> % best </TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> <a href=""#mean_marker""> out of cache <BR> mean perf <BR> Mflops </a></TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> out of cache <BR> % best </TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> details </TH>" << endl ;
  cout << "    <TH ALIGN=CENTER> comments </TH>" << endl ;
  cout << "  </TR>" << endl ;

  set<Lib_Mean>::iterator is ;

  is=s_lib_mean.begin();
  Lib_Mean best(*is);  
  

  for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){

    cout << "  <TR>" << endl ;
    cout << "     <TD> " << is->_lib_name << " </TD>" << endl ;
    cout << "     <TD> " << is->_mean_in_cache << " </TD>" << endl ;
    cout << "     <TD> " << 100*(is->_mean_in_cache/best._mean_in_cache) << " </TD>" << endl ;
    cout << "     <TD> " << is->_mean_out_of_cache << " </TD>" << endl ;
    cout << "     <TD> " << 100*(is->_mean_out_of_cache/best._mean_out_of_cache) << " </TD>" << endl ;
    cout << "     <TD> " << 
      "<a href=\"#"<<is->_lib_name<<"_"<<argv[1]<<"\">snippet</a>/" 
      "<a href=\"#"<<is->_lib_name<<"_flags\">flags</a>  </TD>" << endl ;
    cout << "     <TD> " << 
      "<a href=\"#"<<is->_lib_name<<"_comments\">click here</a>  </TD>" << endl ;
    cout << "  </TR>" << endl ;
  
  }

  cout << "</TABLE>" << endl ;

  ofstream output_file ("../order_lib",ios::out) ;
  
  for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){
    output_file << is->_lib_name << endl ;
  }

  output_file.close();

}

double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max){
  
  int size=tab_sizes.size();
  int nb_sample=0;
  double mean=0.0;

  for (int i=0;i<size;i++){
    
    
    if ((tab_sizes[i]>=size_min)&&(tab_sizes[i]<=size_max)){
      
      nb_sample++;
      mean+=tab_mflops[i];

    }

    
  }

  if (nb_sample==0){
    INFOS("no data for mean calculation");
    return 0.0;
  }

  return mean/nb_sample;
}