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.

128 lines
3.4 KiB

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