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


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:28