action_trisolve.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  action_trisolve.hh
00003 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00004 //=====================================================
00005 //
00006 // This program is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU General Public License
00008 // as published by the Free Software Foundation; either version 2
00009 // of the License, or (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 #ifndef ACTION_TRISOLVE
00020 #define ACTION_TRISOLVE
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_trisolve {
00032 
00033 public :
00034 
00035   // Ctor
00036 
00037   Action_trisolve( int size ):_size(size)
00038   {
00039     MESSAGE("Action_trisolve Ctor");
00040 
00041     // STL vector initialization
00042     init_matrix<pseudo_random>(L_stl,_size);
00043     init_vector<pseudo_random>(B_stl,_size);
00044     init_vector<null_function>(X_stl,_size);
00045     for (int j=0; j<_size; ++j)
00046     {
00047       for (int i=0; i<j; ++i)
00048         L_stl[j][i] = 0;
00049       L_stl[j][j] += 3;
00050     }
00051 
00052     init_vector<null_function>(resu_stl,_size);
00053 
00054     // generic matrix and vector initialization
00055     Interface::matrix_from_stl(L,L_stl);
00056     Interface::vector_from_stl(X,X_stl);
00057     Interface::vector_from_stl(B,B_stl);
00058 
00059     _cost = 0;
00060     for (int j=0; j<_size; ++j)
00061     {
00062       _cost += 2*j + 1;
00063     }
00064   }
00065 
00066   // invalidate copy ctor
00067 
00068   Action_trisolve( const  Action_trisolve & )
00069   {
00070     INFOS("illegal call to Action_trisolve Copy Ctor");
00071     exit(1);
00072   }
00073 
00074   // Dtor
00075 
00076   ~Action_trisolve( void ){
00077 
00078     MESSAGE("Action_trisolve Dtor");
00079 
00080     // deallocation
00081     Interface::free_matrix(L,_size);
00082     Interface::free_vector(B);
00083     Interface::free_vector(X);
00084   }
00085 
00086   // action name
00087 
00088   static inline std::string name( void )
00089   {
00090     return "trisolve_vector_"+Interface::name();
00091   }
00092 
00093   double nb_op_base( void ){
00094     return _cost;
00095   }
00096 
00097   inline void initialize( void ){
00098     //Interface::copy_vector(X_ref,X,_size);
00099   }
00100 
00101   inline void calculate( void ) {
00102       Interface::trisolve_lower(L,B,X,_size);
00103   }
00104 
00105   void check_result(){
00106     if (_size>128) return;
00107     // calculation check
00108     Interface::vector_to_stl(X,resu_stl);
00109 
00110     STL_interface<typename Interface::real_type>::trisolve_lower(L_stl,B_stl,X_stl,_size);
00111 
00112     typename Interface::real_type error=
00113       STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
00114 
00115     if (error>1.e-4){
00116       INFOS("WRONG CALCULATION...residual=" << error);
00117       exit(2);
00118     } //else INFOS("CALCULATION OK...residual=" << error);
00119 
00120   }
00121 
00122 private :
00123 
00124   typename Interface::stl_matrix L_stl;
00125   typename Interface::stl_vector X_stl;
00126   typename Interface::stl_vector B_stl;
00127   typename Interface::stl_vector resu_stl;
00128 
00129   typename Interface::gene_matrix L;
00130   typename Interface::gene_vector X;
00131   typename Interface::gene_vector B;
00132 
00133   int _size;
00134   double _cost;
00135 };
00136 
00137 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:42