1//===================================================== 2// File : action_axpy.hh 3// Author : L. Plagne <laurent.plagne@edf.fr)> 4// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 5//===================================================== 6// 7// This program is free software; you can redistribute it and/or 8// modify it under the terms of the GNU General Public License 9// as published by the Free Software Foundation; either version 2 10// of the License, or (at your option) any later version. 11// 12// This program is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16// You should have received a copy of the GNU General Public License 17// along with this program; if not, write to the Free Software 18// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19// 20#ifndef ACTION_AXPY 21#define ACTION_AXPY 22#include "utilities.h" 23#include "STL_interface.hh" 24#include <string> 25#include "init/init_function.hh" 26#include "init/init_vector.hh" 27#include "init/init_matrix.hh" 28 29using namespace std; 30 31template<class Interface> 32class Action_axpy { 33 34public : 35 36 // Ctor 37 38 Action_axpy( int size ):_size(size),_coef(1.0) 39 { 40 MESSAGE("Action_axpy Ctor"); 41 42 // STL vector initialization 43 44 init_vector<pseudo_random>(X_stl,_size); 45 init_vector<pseudo_random>(Y_stl,_size); 46 init_vector<null_function>(resu_stl,_size); 47 48 // generic matrix and vector initialization 49 50 Interface::vector_from_stl(X_ref,X_stl); 51 Interface::vector_from_stl(Y_ref,Y_stl); 52 53 Interface::vector_from_stl(X,X_stl); 54 Interface::vector_from_stl(Y,Y_stl); 55 56 57 } 58 59 // invalidate copy ctor 60 61 Action_axpy( const Action_axpy & ) 62 { 63 INFOS("illegal call to Action_axpy Copy Ctor"); 64 exit(1); 65 } 66 67 // Dtor 68 69 ~Action_axpy( void ){ 70 71 MESSAGE("Action_axpy Dtor"); 72 73 // deallocation 74 75 Interface::free_vector(X_ref); 76 Interface::free_vector(Y_ref); 77 78 Interface::free_vector(X); 79 Interface::free_vector(Y); 80 } 81 82 // action name 83 84 static inline std::string name( void ) 85 { 86 return "axpy_"+Interface::name(); 87 } 88 89 double nb_op_base( void ){ 90 return 2.0*_size; 91 } 92 93 inline void initialize( void ){ 94 Interface::copy_vector(X_ref,X,_size); 95 Interface::copy_vector(Y_ref,Y,_size); 96 } 97 98 inline void calculate( void ) { 99 BTL_ASM_COMMENT("mybegin axpy"); 100 Interface::axpy(_coef,X,Y,_size); 101 BTL_ASM_COMMENT("myend axpy"); 102 } 103 104 void check_result( void ){ 105 if (_size>128) return; 106 // calculation check 107 108 Interface::vector_to_stl(Y,resu_stl); 109 110 STL_interface<typename Interface::real_type>::axpy(_coef,X_stl,Y_stl,_size); 111 112 typename Interface::real_type error= 113 STL_interface<typename Interface::real_type>::norm_diff(Y_stl,resu_stl); 114 115 if (error>1.e-6){ 116 INFOS("WRONG CALCULATION...residual=" << error); 117 exit(0); 118 } 119 120 } 121 122private : 123 124 typename Interface::stl_vector X_stl; 125 typename Interface::stl_vector Y_stl; 126 typename Interface::stl_vector resu_stl; 127 128 typename Interface::gene_vector X_ref; 129 typename Interface::gene_vector Y_ref; 130 131 typename Interface::gene_vector X; 132 typename Interface::gene_vector Y; 133 134 typename Interface::real_type _coef; 135 136 int _size; 137}; 138 139#endif 140