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