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 ACTION_MATRIX_MATRIX_PRODUCT_BIS
00021 #define ACTION_MATRIX_MATRIX_PRODUCT_BIS
00022 #include "utilities.h"
00023 #include "STL_interface.hh"
00024 #include "STL_timer.hh"
00025 #include <string>
00026 #include "init_function.hh"
00027 #include "init_vector.hh"
00028 #include "init_matrix.hh"
00029
00030 using namespace std;
00031
00032 template<class Interface>
00033 class Action_matrix_matrix_product_bis {
00034
00035 public :
00036
00037 static inline std::string name( void )
00038 {
00039 return "matrix_matrix_"+Interface::name();
00040 }
00041
00042 static double nb_op_base(int size){
00043 return 2.0*size*size*size;
00044 }
00045
00046 static double calculate( int nb_calc, int size ) {
00047
00048
00049
00050 typename Interface::stl_matrix A_stl;
00051 typename Interface::stl_matrix B_stl;
00052 typename Interface::stl_matrix X_stl;
00053
00054 init_matrix<pseudo_random>(A_stl,size);
00055 init_matrix<pseudo_random>(B_stl,size);
00056 init_matrix<null_function>(X_stl,size);
00057
00058
00059
00060 typename Interface::gene_matrix A_ref;
00061 typename Interface::gene_matrix B_ref;
00062 typename Interface::gene_matrix X_ref;
00063
00064 typename Interface::gene_matrix A;
00065 typename Interface::gene_matrix B;
00066 typename Interface::gene_matrix X;
00067
00068
00069 Interface::matrix_from_stl(A_ref,A_stl);
00070 Interface::matrix_from_stl(B_ref,B_stl);
00071 Interface::matrix_from_stl(X_ref,X_stl);
00072
00073 Interface::matrix_from_stl(A,A_stl);
00074 Interface::matrix_from_stl(B,B_stl);
00075 Interface::matrix_from_stl(X,X_stl);
00076
00077
00078
00079
00080 STL_timer chronos;
00081
00082
00083
00084 chronos.start_baseline(nb_calc);
00085
00086 do {
00087
00088 Interface::copy_matrix(A_ref,A,size);
00089 Interface::copy_matrix(B_ref,B,size);
00090 Interface::copy_matrix(X_ref,X,size);
00091
00092
00093
00094 }
00095 while(chronos.check());
00096
00097 chronos.report(true);
00098
00099
00100
00101 chronos.start(nb_calc);
00102
00103 do {
00104
00105 Interface::copy_matrix(A_ref,A,size);
00106 Interface::copy_matrix(B_ref,B,size);
00107 Interface::copy_matrix(X_ref,X,size);
00108
00109 Interface::matrix_matrix_product(A,B,X,size);
00110 }
00111 while(chronos.check());
00112
00113 chronos.report(true);
00114
00115 double time=chronos.calculated_time/2000.0;
00116
00117
00118
00119 typename Interface::stl_matrix resu_stl(size);
00120
00121 Interface::matrix_to_stl(X,resu_stl);
00122
00123 STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,size);
00124
00125 typename Interface::real_type error=
00126 STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
00127
00128 if (error>1.e-6){
00129 INFOS("WRONG CALCULATION...residual=" << error);
00130 exit(1);
00131 }
00132
00133
00134
00135 Interface::free_matrix(A,size);
00136 Interface::free_matrix(B,size);
00137 Interface::free_matrix(X,size);
00138
00139 Interface::free_matrix(A_ref,size);
00140 Interface::free_matrix(B_ref,size);
00141 Interface::free_matrix(X_ref,size);
00142
00143 return time;
00144 }
00145
00146 };
00147
00148
00149 #endif
00150
00151
00152