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_LU_SOLVE
00021 #define ACTION_LU_SOLVE
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_lu_solve
00033 {
00034
00035 public :
00036
00037 static inline std::string name( void )
00038 {
00039 return "lu_solve_"+Interface::name();
00040 }
00041
00042 static double nb_op_base(int size){
00043 return 2.0*size*size*size/3.0;
00044 }
00045
00046
00047 static double calculate( int nb_calc, int size ) {
00048
00049
00050
00051 typename Interface::stl_matrix A_stl;
00052 typename Interface::stl_vector B_stl;
00053 typename Interface::stl_vector X_stl;
00054
00055 init_matrix<pseudo_random>(A_stl,size);
00056 init_vector<pseudo_random>(B_stl,size);
00057 init_vector<null_function>(X_stl,size);
00058
00059
00060
00061 typename Interface::gene_matrix A;
00062 typename Interface::gene_vector B;
00063 typename Interface::gene_vector X;
00064
00065 typename Interface::gene_matrix LU;
00066
00067 Interface::matrix_from_stl(A,A_stl);
00068 Interface::vector_from_stl(B,B_stl);
00069 Interface::vector_from_stl(X,X_stl);
00070 Interface::matrix_from_stl(LU,A_stl);
00071
00072
00073
00074 typename Interface::Pivot_Vector pivot;
00075 Interface::new_Pivot_Vector(pivot,size);
00076
00077
00078
00079 Portable_Timer chronos;
00080
00081
00082
00083 chronos.start();
00084
00085 for (int ii=0;ii<nb_calc;ii++){
00086
00087
00088 Interface::copy_matrix(A,LU,size);
00089 Interface::LU_factor(LU,pivot,size);
00090
00091
00092
00093 Interface::LU_solve(LU,pivot,B,X,size);
00094
00095 }
00096
00097
00098
00099 chronos.stop();
00100
00101 double time=chronos.user_time();
00102
00103
00104
00105 typename Interface::stl_vector B_new_stl(size);
00106 Interface::vector_to_stl(X,X_stl);
00107
00108 STL_interface<typename Interface::real_type>::matrix_vector_product(A_stl,X_stl,B_new_stl,size);
00109
00110 typename Interface::real_type error=
00111 STL_interface<typename Interface::real_type>::norm_diff(B_stl,B_new_stl);
00112
00113 if (error>1.e-5){
00114 INFOS("WRONG CALCULATION...residual=" << error);
00115 STL_interface<typename Interface::real_type>::display_vector(B_stl);
00116 STL_interface<typename Interface::real_type>::display_vector(B_new_stl);
00117 exit(0);
00118 }
00119
00120
00121
00122 Interface::free_matrix(A,size);
00123 Interface::free_vector(B);
00124 Interface::free_vector(X);
00125 Interface::free_Pivot_Vector(pivot);
00126
00127 return time;
00128 }
00129
00130 };
00131
00132
00133 #endif
00134
00135
00136