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.6 KiB

  1. //=====================================================
  2. // File : action_symv.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_SYMV
  21. #define ACTION_SYMV
  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_symv {
  31. public :
  32. // Ctor
  33. BTL_DONT_INLINE Action_symv( int size ):_size(size)
  34. {
  35. MESSAGE("Action_symv Ctor");
  36. // STL matrix and vector initialization
  37. init_matrix_symm<pseudo_random>(A_stl,_size);
  38. init_vector<pseudo_random>(B_stl,_size);
  39. init_vector<null_function>(X_stl,_size);
  40. init_vector<null_function>(resu_stl,_size);
  41. // generic matrix and vector initialization
  42. Interface::matrix_from_stl(A_ref,A_stl);
  43. Interface::matrix_from_stl(A,A_stl);
  44. Interface::vector_from_stl(B_ref,B_stl);
  45. Interface::vector_from_stl(B,B_stl);
  46. Interface::vector_from_stl(X_ref,X_stl);
  47. Interface::vector_from_stl(X,X_stl);
  48. }
  49. // invalidate copy ctor
  50. Action_symv( const Action_symv & )
  51. {
  52. INFOS("illegal call to Action_symv Copy Ctor");
  53. exit(1);
  54. }
  55. // Dtor
  56. BTL_DONT_INLINE ~Action_symv( void ){
  57. Interface::free_matrix(A,_size);
  58. Interface::free_vector(B);
  59. Interface::free_vector(X);
  60. Interface::free_matrix(A_ref,_size);
  61. Interface::free_vector(B_ref);
  62. Interface::free_vector(X_ref);
  63. }
  64. // action name
  65. static inline std::string name( void )
  66. {
  67. return "symv_" + Interface::name();
  68. }
  69. double nb_op_base( void ){
  70. return 2.0*_size*_size;
  71. }
  72. BTL_DONT_INLINE void initialize( void ){
  73. Interface::copy_matrix(A_ref,A,_size);
  74. Interface::copy_vector(B_ref,B,_size);
  75. Interface::copy_vector(X_ref,X,_size);
  76. }
  77. BTL_DONT_INLINE void calculate( void ) {
  78. BTL_ASM_COMMENT("#begin symv");
  79. Interface::symv(A,B,X,_size);
  80. BTL_ASM_COMMENT("end symv");
  81. }
  82. BTL_DONT_INLINE void check_result( void ){
  83. if (_size>128) return;
  84. // calculation check
  85. Interface::vector_to_stl(X,resu_stl);
  86. STL_interface<typename Interface::real_type>::symv(A_stl,B_stl,X_stl,_size);
  87. typename Interface::real_type error=
  88. STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
  89. if (error>1.e-5){
  90. INFOS("WRONG CALCULATION...residual=" << error);
  91. exit(0);
  92. }
  93. }
  94. private :
  95. typename Interface::stl_matrix A_stl;
  96. typename Interface::stl_vector B_stl;
  97. typename Interface::stl_vector X_stl;
  98. typename Interface::stl_vector resu_stl;
  99. typename Interface::gene_matrix A_ref;
  100. typename Interface::gene_vector B_ref;
  101. typename Interface::gene_vector X_ref;
  102. typename Interface::gene_matrix A;
  103. typename Interface::gene_vector B;
  104. typename Interface::gene_vector X;
  105. int _size;
  106. };
  107. #endif