You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.3 KiB

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