1*bf2c3715SXin Li 2*bf2c3715SXin Li // This program is free software; you can redistribute it and/or 3*bf2c3715SXin Li // modify it under the terms of the GNU General Public License 4*bf2c3715SXin Li // as published by the Free Software Foundation; either version 2 5*bf2c3715SXin Li // of the License, or (at your option) any later version. 6*bf2c3715SXin Li // 7*bf2c3715SXin Li // This program is distributed in the hope that it will be useful, 8*bf2c3715SXin Li // but WITHOUT ANY WARRANTY; without even the implied warranty of 9*bf2c3715SXin Li // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10*bf2c3715SXin Li // GNU General Public License for more details. 11*bf2c3715SXin Li // You should have received a copy of the GNU General Public License 12*bf2c3715SXin Li // along with this program; if not, write to the Free Software 13*bf2c3715SXin Li // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 14*bf2c3715SXin Li // 15*bf2c3715SXin Li #ifndef ACTION_ROT 16*bf2c3715SXin Li #define ACTION_ROT 17*bf2c3715SXin Li #include "utilities.h" 18*bf2c3715SXin Li #include "STL_interface.hh" 19*bf2c3715SXin Li #include <string> 20*bf2c3715SXin Li #include "init/init_function.hh" 21*bf2c3715SXin Li #include "init/init_vector.hh" 22*bf2c3715SXin Li #include "init/init_matrix.hh" 23*bf2c3715SXin Li 24*bf2c3715SXin Li using namespace std; 25*bf2c3715SXin Li 26*bf2c3715SXin Li template<class Interface> 27*bf2c3715SXin Li class Action_rot { 28*bf2c3715SXin Li 29*bf2c3715SXin Li public : 30*bf2c3715SXin Li 31*bf2c3715SXin Li // Ctor Action_rot(int size)32*bf2c3715SXin Li BTL_DONT_INLINE Action_rot( int size ):_size(size) 33*bf2c3715SXin Li { 34*bf2c3715SXin Li MESSAGE("Action_rot Ctor"); 35*bf2c3715SXin Li 36*bf2c3715SXin Li // STL matrix and vector initialization 37*bf2c3715SXin Li typename Interface::stl_matrix tmp; 38*bf2c3715SXin Li init_vector<pseudo_random>(A_stl,_size); 39*bf2c3715SXin Li init_vector<pseudo_random>(B_stl,_size); 40*bf2c3715SXin Li 41*bf2c3715SXin Li // generic matrix and vector initialization 42*bf2c3715SXin Li Interface::vector_from_stl(A_ref,A_stl); 43*bf2c3715SXin Li Interface::vector_from_stl(A,A_stl); 44*bf2c3715SXin Li Interface::vector_from_stl(B_ref,B_stl); 45*bf2c3715SXin Li Interface::vector_from_stl(B,B_stl); 46*bf2c3715SXin Li } 47*bf2c3715SXin Li 48*bf2c3715SXin Li // invalidate copy ctor Action_rot(const Action_rot &)49*bf2c3715SXin Li Action_rot( const Action_rot & ) 50*bf2c3715SXin Li { 51*bf2c3715SXin Li INFOS("illegal call to Action_rot Copy Ctor"); 52*bf2c3715SXin Li exit(1); 53*bf2c3715SXin Li } 54*bf2c3715SXin Li 55*bf2c3715SXin Li // Dtor ~Action_rot(void)56*bf2c3715SXin Li BTL_DONT_INLINE ~Action_rot( void ){ 57*bf2c3715SXin Li MESSAGE("Action_rot Dtor"); 58*bf2c3715SXin Li Interface::free_vector(A); 59*bf2c3715SXin Li Interface::free_vector(B); 60*bf2c3715SXin Li Interface::free_vector(A_ref); 61*bf2c3715SXin Li Interface::free_vector(B_ref); 62*bf2c3715SXin Li } 63*bf2c3715SXin Li 64*bf2c3715SXin Li // action name name(void)65*bf2c3715SXin Li static inline std::string name( void ) 66*bf2c3715SXin Li { 67*bf2c3715SXin Li return "rot_" + Interface::name(); 68*bf2c3715SXin Li } 69*bf2c3715SXin Li nb_op_base(void)70*bf2c3715SXin Li double nb_op_base( void ){ 71*bf2c3715SXin Li return 6.0*_size; 72*bf2c3715SXin Li } 73*bf2c3715SXin Li initialize(void)74*bf2c3715SXin Li BTL_DONT_INLINE void initialize( void ){ 75*bf2c3715SXin Li Interface::copy_vector(A_ref,A,_size); 76*bf2c3715SXin Li Interface::copy_vector(B_ref,B,_size); 77*bf2c3715SXin Li } 78*bf2c3715SXin Li calculate(void)79*bf2c3715SXin Li BTL_DONT_INLINE void calculate( void ) { 80*bf2c3715SXin Li BTL_ASM_COMMENT("#begin rot"); 81*bf2c3715SXin Li Interface::rot(A,B,0.5,0.6,_size); 82*bf2c3715SXin Li BTL_ASM_COMMENT("end rot"); 83*bf2c3715SXin Li } 84*bf2c3715SXin Li check_result(void)85*bf2c3715SXin Li BTL_DONT_INLINE void check_result( void ){ 86*bf2c3715SXin Li // calculation check 87*bf2c3715SXin Li // Interface::vector_to_stl(X,resu_stl); 88*bf2c3715SXin Li 89*bf2c3715SXin Li // STL_interface<typename Interface::real_type>::rot(A_stl,B_stl,X_stl,_size); 90*bf2c3715SXin Li 91*bf2c3715SXin Li // typename Interface::real_type error= 92*bf2c3715SXin Li // STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); 93*bf2c3715SXin Li 94*bf2c3715SXin Li // if (error>1.e-3){ 95*bf2c3715SXin Li // INFOS("WRONG CALCULATION...residual=" << error); 96*bf2c3715SXin Li // exit(0); 97*bf2c3715SXin Li // } 98*bf2c3715SXin Li 99*bf2c3715SXin Li } 100*bf2c3715SXin Li 101*bf2c3715SXin Li private : 102*bf2c3715SXin Li 103*bf2c3715SXin Li typename Interface::stl_vector A_stl; 104*bf2c3715SXin Li typename Interface::stl_vector B_stl; 105*bf2c3715SXin Li 106*bf2c3715SXin Li typename Interface::gene_vector A_ref; 107*bf2c3715SXin Li typename Interface::gene_vector B_ref; 108*bf2c3715SXin Li 109*bf2c3715SXin Li typename Interface::gene_vector A; 110*bf2c3715SXin Li typename Interface::gene_vector B; 111*bf2c3715SXin Li 112*bf2c3715SXin Li int _size; 113*bf2c3715SXin Li }; 114*bf2c3715SXin Li 115*bf2c3715SXin Li 116*bf2c3715SXin Li #endif 117