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