Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00033
00034
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
00051
00052 std::vector<double> tab_mflops(nb_point);
00053 std::vector<int> tab_sizes(nb_point);
00054
00055
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
00064 Perf_Analyzer<Action> perf_action;
00065 for (int i=nb_point-1;i>=0;i--)
00066 {
00067
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
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
00147 dump_xy_file(tab_sizes,tab_mflops,filename);
00148
00149 }
00150
00151
00152
00153 template <class Action>
00154 BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point ){
00155
00156
00157 bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point);
00158
00159
00160
00161
00162
00163
00164
00165
00166 }
00167
00168 #endif