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.

139 lines
3.3 KiB

  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. using namespace std;
  29. template<class Interface>
  30. class Action_axpy {
  31. public :
  32. // Ctor
  33. Action_axpy( int size ):_size(size),_coef(1.0)
  34. {
  35. MESSAGE("Action_axpy Ctor");
  36. // STL vector initialization
  37. init_vector<pseudo_random>(X_stl,_size);
  38. init_vector<pseudo_random>(Y_stl,_size);
  39. init_vector<null_function>(resu_stl,_size);
  40. // generic matrix and vector initialization
  41. Interface::vector_from_stl(X_ref,X_stl);
  42. Interface::vector_from_stl(Y_ref,Y_stl);
  43. Interface::vector_from_stl(X,X_stl);
  44. Interface::vector_from_stl(Y,Y_stl);
  45. }
  46. // invalidate copy ctor
  47. Action_axpy( const Action_axpy & )
  48. {
  49. INFOS("illegal call to Action_axpy Copy Ctor");
  50. exit(1);
  51. }
  52. // Dtor
  53. ~Action_axpy( void ){
  54. MESSAGE("Action_axpy Dtor");
  55. // deallocation
  56. Interface::free_vector(X_ref);
  57. Interface::free_vector(Y_ref);
  58. Interface::free_vector(X);
  59. Interface::free_vector(Y);
  60. }
  61. // action name
  62. static inline std::string name( void )
  63. {
  64. return "axpy_"+Interface::name();
  65. }
  66. double nb_op_base( void ){
  67. return 2.0*_size;
  68. }
  69. inline void initialize( void ){
  70. Interface::copy_vector(X_ref,X,_size);
  71. Interface::copy_vector(Y_ref,Y,_size);
  72. }
  73. inline void calculate( void ) {
  74. BTL_ASM_COMMENT("mybegin axpy");
  75. Interface::axpy(_coef,X,Y,_size);
  76. BTL_ASM_COMMENT("myend axpy");
  77. }
  78. void check_result( void ){
  79. if (_size>128) return;
  80. // calculation check
  81. Interface::vector_to_stl(Y,resu_stl);
  82. STL_interface<typename Interface::real_type>::axpy(_coef,X_stl,Y_stl,_size);
  83. typename Interface::real_type error=
  84. STL_interface<typename Interface::real_type>::norm_diff(Y_stl,resu_stl);
  85. if (error>1.e-6){
  86. INFOS("WRONG CALCULATION...residual=" << error);
  87. exit(0);
  88. }
  89. }
  90. private :
  91. typename Interface::stl_vector X_stl;
  92. typename Interface::stl_vector Y_stl;
  93. typename Interface::stl_vector resu_stl;
  94. typename Interface::gene_vector X_ref;
  95. typename Interface::gene_vector Y_ref;
  96. typename Interface::gene_vector X;
  97. typename Interface::gene_vector Y;
  98. typename Interface::real_type _coef;
  99. int _size;
  100. };
  101. #endif