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 #ifndef ACTION_AXPBY
00020 #define ACTION_AXPBY
00021 #include "utilities.h"
00022 #include "STL_interface.hh"
00023 #include <string>
00024 #include "init/init_function.hh"
00025 #include "init/init_vector.hh"
00026 #include "init/init_matrix.hh"
00027
00028 using namespace std;
00029
00030 template<class Interface>
00031 class Action_axpby {
00032
00033 public :
00034
00035
00036 Action_axpby( int size ):_size(size),_alpha(0.5),_beta(0.95)
00037 {
00038 MESSAGE("Action_axpby Ctor");
00039
00040
00041 init_vector<pseudo_random>(X_stl,_size);
00042 init_vector<pseudo_random>(Y_stl,_size);
00043 init_vector<null_function>(resu_stl,_size);
00044
00045
00046 Interface::vector_from_stl(X_ref,X_stl);
00047 Interface::vector_from_stl(Y_ref,Y_stl);
00048
00049 Interface::vector_from_stl(X,X_stl);
00050 Interface::vector_from_stl(Y,Y_stl);
00051 }
00052
00053
00054 Action_axpby( const Action_axpby & )
00055 {
00056 INFOS("illegal call to Action_axpby Copy Ctor");
00057 exit(1);
00058 }
00059
00060
00061 ~Action_axpby( void ){
00062 MESSAGE("Action_axpby Dtor");
00063
00064
00065 Interface::free_vector(X_ref);
00066 Interface::free_vector(Y_ref);
00067
00068 Interface::free_vector(X);
00069 Interface::free_vector(Y);
00070 }
00071
00072
00073 static inline std::string name( void )
00074 {
00075 return "axpby_"+Interface::name();
00076 }
00077
00078 double nb_op_base( void ){
00079 return 3.0*_size;
00080 }
00081
00082 inline void initialize( void ){
00083 Interface::copy_vector(X_ref,X,_size);
00084 Interface::copy_vector(Y_ref,Y,_size);
00085 }
00086
00087 inline void calculate( void ) {
00088 BTL_ASM_COMMENT("mybegin axpby");
00089 Interface::axpby(_alpha,X,_beta,Y,_size);
00090 BTL_ASM_COMMENT("myend axpby");
00091 }
00092
00093 void check_result( void ){
00094 if (_size>128) return;
00095
00096 Interface::vector_to_stl(Y,resu_stl);
00097
00098 STL_interface<typename Interface::real_type>::axpby(_alpha,X_stl,_beta,Y_stl,_size);
00099
00100 typename Interface::real_type error=
00101 STL_interface<typename Interface::real_type>::norm_diff(Y_stl,resu_stl);
00102
00103 if (error>1.e-6){
00104 INFOS("WRONG CALCULATION...residual=" << error);
00105 exit(2);
00106 }
00107 }
00108
00109 private :
00110
00111 typename Interface::stl_vector X_stl;
00112 typename Interface::stl_vector Y_stl;
00113 typename Interface::stl_vector resu_stl;
00114
00115 typename Interface::gene_vector X_ref;
00116 typename Interface::gene_vector Y_ref;
00117
00118 typename Interface::gene_vector X;
00119 typename Interface::gene_vector Y;
00120
00121 typename Interface::real_type _alpha;
00122 typename Interface::real_type _beta;
00123
00124 int _size;
00125 };
00126
00127 #endif