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