action_ger.hh
Go to the documentation of this file.
00001 
00002 // This program is free software; you can redistribute it and/or
00003 // modify it under the terms of the GNU General Public License
00004 // as published by the Free Software Foundation; either version 2
00005 // of the License, or (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 // You should have received a copy of the GNU General Public License
00012 // along with this program; if not, write to the Free Software
00013 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00014 //
00015 #ifndef ACTION_GER
00016 #define ACTION_GER
00017 #include "utilities.h"
00018 #include "STL_interface.hh"
00019 #include <string>
00020 #include "init/init_function.hh"
00021 #include "init/init_vector.hh"
00022 #include "init/init_matrix.hh"
00023 
00024 using namespace std;
00025 
00026 template<class Interface>
00027 class Action_ger {
00028 
00029 public :
00030 
00031   // Ctor
00032   BTL_DONT_INLINE Action_ger( int size ):_size(size)
00033   {
00034     MESSAGE("Action_ger Ctor");
00035 
00036     // STL matrix and vector initialization
00037     typename Interface::stl_matrix tmp;
00038     init_matrix<pseudo_random>(A_stl,_size);
00039     init_vector<pseudo_random>(B_stl,_size);
00040     init_vector<pseudo_random>(X_stl,_size);
00041     init_vector<null_function>(resu_stl,_size);
00042 
00043     // generic matrix and vector initialization
00044     Interface::matrix_from_stl(A_ref,A_stl);
00045     Interface::matrix_from_stl(A,A_stl);
00046     Interface::vector_from_stl(B_ref,B_stl);
00047     Interface::vector_from_stl(B,B_stl);
00048     Interface::vector_from_stl(X_ref,X_stl);
00049     Interface::vector_from_stl(X,X_stl);
00050   }
00051 
00052   // invalidate copy ctor
00053   Action_ger( const  Action_ger & )
00054   {
00055     INFOS("illegal call to Action_ger Copy Ctor");
00056     exit(1);
00057   }
00058 
00059   // Dtor
00060   BTL_DONT_INLINE ~Action_ger( void ){
00061     MESSAGE("Action_ger Dtor");
00062     Interface::free_matrix(A,_size);
00063     Interface::free_vector(B);
00064     Interface::free_vector(X);
00065     Interface::free_matrix(A_ref,_size);
00066     Interface::free_vector(B_ref);
00067     Interface::free_vector(X_ref);
00068 
00069   }
00070 
00071   // action name
00072   static inline std::string name( void )
00073   {
00074     return "ger_" + Interface::name();
00075   }
00076 
00077   double nb_op_base( void ){
00078     return 2.0*_size*_size;
00079   }
00080 
00081   BTL_DONT_INLINE  void initialize( void ){
00082     Interface::copy_matrix(A_ref,A,_size);
00083     Interface::copy_vector(B_ref,B,_size);
00084     Interface::copy_vector(X_ref,X,_size);
00085   }
00086 
00087   BTL_DONT_INLINE void calculate( void ) {
00088     BTL_ASM_COMMENT("#begin ger");
00089     Interface::ger(A,B,X,_size);
00090     BTL_ASM_COMMENT("end ger");
00091   }
00092 
00093   BTL_DONT_INLINE void check_result( void ){
00094     // calculation check
00095     Interface::vector_to_stl(X,resu_stl);
00096 
00097     STL_interface<typename Interface::real_type>::ger(A_stl,B_stl,X_stl,_size);
00098 
00099     typename Interface::real_type error=
00100       STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
00101 
00102     if (error>1.e-3){
00103       INFOS("WRONG CALCULATION...residual=" << error);
00104 //       exit(0);
00105     }
00106 
00107   }
00108 
00109 private :
00110 
00111   typename Interface::stl_matrix A_stl;
00112   typename Interface::stl_vector B_stl;
00113   typename Interface::stl_vector X_stl;
00114   typename Interface::stl_vector resu_stl;
00115 
00116   typename Interface::gene_matrix A_ref;
00117   typename Interface::gene_vector B_ref;
00118   typename Interface::gene_vector X_ref;
00119 
00120   typename Interface::gene_matrix A;
00121   typename Interface::gene_vector B;
00122   typename Interface::gene_vector X;
00123 
00124   int _size;
00125 };
00126 
00127 
00128 #endif


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