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_ATV_PRODUCT
00021 #define ACTION_ATV_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_atv_product {
00033
00034 public :
00035
00036 Action_atv_product( int size ) : _size(size)
00037 {
00038 MESSAGE("Action_atv_product Ctor");
00039
00040
00041
00042 init_matrix<pseudo_random>(A_stl,_size);
00043 init_vector<pseudo_random>(B_stl,_size);
00044 init_vector<null_function>(X_stl,_size);
00045 init_vector<null_function>(resu_stl,_size);
00046
00047
00048
00049 Interface::matrix_from_stl(A_ref,A_stl);
00050 Interface::vector_from_stl(B_ref,B_stl);
00051 Interface::vector_from_stl(X_ref,X_stl);
00052
00053 Interface::matrix_from_stl(A,A_stl);
00054 Interface::vector_from_stl(B,B_stl);
00055 Interface::vector_from_stl(X,X_stl);
00056 }
00057
00058
00059 Action_atv_product( const Action_atv_product & )
00060 {
00061 INFOS("illegal call to Action_atv_product Copy Ctor");
00062 exit(1);
00063 }
00064
00065 ~Action_atv_product( void )
00066 {
00067 MESSAGE("Action_atv_product Dtor");
00068
00069 Interface::free_matrix(A,_size);
00070 Interface::free_vector(B);
00071 Interface::free_vector(X);
00072
00073 Interface::free_matrix(A_ref,_size);
00074 Interface::free_vector(B_ref);
00075 Interface::free_vector(X_ref);
00076 }
00077
00078 static inline std::string name() { return "atv_" + Interface::name(); }
00079
00080 double nb_op_base( void ) { return 2.0*_size*_size; }
00081
00082 inline void initialize( void ){
00083 Interface::copy_matrix(A_ref,A,_size);
00084 Interface::copy_vector(B_ref,B,_size);
00085 Interface::copy_vector(X_ref,X,_size);
00086 }
00087
00088 BTL_DONT_INLINE void calculate( void ) {
00089 BTL_ASM_COMMENT("begin atv");
00090 Interface::atv_product(A,B,X,_size);
00091 BTL_ASM_COMMENT("end atv");
00092 }
00093
00094 void check_result( void )
00095 {
00096 if (_size>128) return;
00097 Interface::vector_to_stl(X,resu_stl);
00098
00099 STL_interface<typename Interface::real_type>::atv_product(A_stl,B_stl,X_stl,_size);
00100
00101 typename Interface::real_type error=
00102 STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
00103
00104 if (error>1.e-6){
00105 INFOS("WRONG CALCULATION...residual=" << error);
00106 exit(1);
00107 }
00108 }
00109
00110 private :
00111
00112 typename Interface::stl_matrix A_stl;
00113 typename Interface::stl_vector B_stl;
00114 typename Interface::stl_vector X_stl;
00115 typename Interface::stl_vector resu_stl;
00116
00117 typename Interface::gene_matrix A_ref;
00118 typename Interface::gene_vector B_ref;
00119 typename Interface::gene_vector X_ref;
00120
00121 typename Interface::gene_matrix A;
00122 typename Interface::gene_vector B;
00123 typename Interface::gene_vector X;
00124
00125
00126 int _size;
00127
00128 };
00129
00130
00131 #endif
00132
00133
00134