action_axpy.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  action_axpy.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_AXPY
00021 #define ACTION_AXPY
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_axpy {
00033 
00034 public :
00035 
00036   // Ctor
00037 
00038   Action_axpy( int size ):_size(size),_coef(1.0)
00039   {
00040     MESSAGE("Action_axpy Ctor");
00041 
00042     // STL vector initialization
00043 
00044     init_vector<pseudo_random>(X_stl,_size);
00045     init_vector<pseudo_random>(Y_stl,_size);
00046     init_vector<null_function>(resu_stl,_size);
00047 
00048     // generic matrix and vector initialization
00049 
00050     Interface::vector_from_stl(X_ref,X_stl);
00051     Interface::vector_from_stl(Y_ref,Y_stl);
00052 
00053     Interface::vector_from_stl(X,X_stl);
00054     Interface::vector_from_stl(Y,Y_stl);
00055 
00056 
00057   }
00058 
00059   // invalidate copy ctor
00060 
00061   Action_axpy( const  Action_axpy & )
00062   {
00063     INFOS("illegal call to Action_axpy Copy Ctor");
00064     exit(1);
00065   }
00066 
00067   // Dtor
00068 
00069   ~Action_axpy( void ){
00070 
00071     MESSAGE("Action_axpy Dtor");
00072 
00073     // deallocation
00074 
00075     Interface::free_vector(X_ref);
00076     Interface::free_vector(Y_ref);
00077 
00078     Interface::free_vector(X);
00079     Interface::free_vector(Y);
00080   }
00081 
00082   // action name
00083 
00084   static inline std::string name( void )
00085   {
00086     return "axpy_"+Interface::name();
00087   }
00088 
00089   double nb_op_base( void ){
00090     return 2.0*_size;
00091   }
00092 
00093   inline void initialize( void ){
00094     Interface::copy_vector(X_ref,X,_size);
00095     Interface::copy_vector(Y_ref,Y,_size);
00096   }
00097 
00098   inline void calculate( void ) {
00099     BTL_ASM_COMMENT("mybegin axpy");
00100     Interface::axpy(_coef,X,Y,_size);
00101     BTL_ASM_COMMENT("myend axpy");
00102   }
00103 
00104   void check_result( void ){
00105     if (_size>128) return;
00106     // calculation check
00107 
00108     Interface::vector_to_stl(Y,resu_stl);
00109 
00110     STL_interface<typename Interface::real_type>::axpy(_coef,X_stl,Y_stl,_size);
00111 
00112     typename Interface::real_type error=
00113       STL_interface<typename Interface::real_type>::norm_diff(Y_stl,resu_stl);
00114 
00115     if (error>1.e-6){
00116       INFOS("WRONG CALCULATION...residual=" << error);
00117       exit(0);
00118     }
00119 
00120   }
00121 
00122 private :
00123 
00124   typename Interface::stl_vector X_stl;
00125   typename Interface::stl_vector Y_stl;
00126   typename Interface::stl_vector resu_stl;
00127 
00128   typename Interface::gene_vector X_ref;
00129   typename Interface::gene_vector Y_ref;
00130 
00131   typename Interface::gene_vector X;
00132   typename Interface::gene_vector Y;
00133 
00134   typename Interface::real_type _coef;
00135 
00136   int _size;
00137 };
00138 
00139 #endif


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