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.

137 lines
3.3 KiB

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