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


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