Home | History | Annotate | Download | only in actions
      1 //=====================================================
      2 // File   :  action_matrix_matrix_product_bis.hh
      3 // Author :  L. Plagne <laurent.plagne (at) 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_MATRIX_MATRIX_PRODUCT_BIS
     21 #define ACTION_MATRIX_MATRIX_PRODUCT_BIS
     22 #include "utilities.h"
     23 #include "STL_interface.hh"
     24 #include "STL_timer.hh"
     25 #include <string>
     26 #include "init_function.hh"
     27 #include "init_vector.hh"
     28 #include "init_matrix.hh"
     29 
     30 using namespace std;
     31 
     32 template<class Interface>
     33 class Action_matrix_matrix_product_bis {
     34 
     35 public :
     36 
     37   static inline std::string name( void )
     38   {
     39     return "matrix_matrix_"+Interface::name();
     40   }
     41 
     42   static double nb_op_base(int size){
     43     return 2.0*size*size*size;
     44   }
     45 
     46   static double calculate( int nb_calc, int size ) {
     47 
     48     // STL matrix and vector initialization
     49 
     50     typename Interface::stl_matrix A_stl;
     51     typename Interface::stl_matrix B_stl;
     52     typename Interface::stl_matrix X_stl;
     53 
     54     init_matrix<pseudo_random>(A_stl,size);
     55     init_matrix<pseudo_random>(B_stl,size);
     56     init_matrix<null_function>(X_stl,size);
     57 
     58     // generic matrix and vector initialization
     59 
     60     typename Interface::gene_matrix A_ref;
     61     typename Interface::gene_matrix B_ref;
     62     typename Interface::gene_matrix X_ref;
     63 
     64     typename Interface::gene_matrix A;
     65     typename Interface::gene_matrix B;
     66     typename Interface::gene_matrix X;
     67 
     68 
     69     Interface::matrix_from_stl(A_ref,A_stl);
     70     Interface::matrix_from_stl(B_ref,B_stl);
     71     Interface::matrix_from_stl(X_ref,X_stl);
     72 
     73     Interface::matrix_from_stl(A,A_stl);
     74     Interface::matrix_from_stl(B,B_stl);
     75     Interface::matrix_from_stl(X,X_stl);
     76 
     77 
     78     // STL_timer utilities
     79 
     80     STL_timer chronos;
     81 
     82     // Baseline evaluation
     83 
     84     chronos.start_baseline(nb_calc);
     85 
     86     do {
     87 
     88       Interface::copy_matrix(A_ref,A,size);
     89       Interface::copy_matrix(B_ref,B,size);
     90       Interface::copy_matrix(X_ref,X,size);
     91 
     92 
     93       //      Interface::matrix_matrix_product(A,B,X,size); This line must be commented !!!!
     94     }
     95     while(chronos.check());
     96 
     97     chronos.report(true);
     98 
     99     // Time measurement
    100 
    101     chronos.start(nb_calc);
    102 
    103     do {
    104 
    105       Interface::copy_matrix(A_ref,A,size);
    106       Interface::copy_matrix(B_ref,B,size);
    107       Interface::copy_matrix(X_ref,X,size);
    108 
    109       Interface::matrix_matrix_product(A,B,X,size); // here it is not commented !!!!
    110     }
    111     while(chronos.check());
    112 
    113     chronos.report(true);
    114 
    115     double time=chronos.calculated_time/2000.0;
    116 
    117     // calculation check
    118 
    119     typename Interface::stl_matrix resu_stl(size);
    120 
    121     Interface::matrix_to_stl(X,resu_stl);
    122 
    123     STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,size);
    124 
    125     typename Interface::real_type error=
    126       STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
    127 
    128     if (error>1.e-6){
    129       INFOS("WRONG CALCULATION...residual=" << error);
    130       exit(1);
    131     }
    132 
    133     // deallocation and return time
    134 
    135     Interface::free_matrix(A,size);
    136     Interface::free_matrix(B,size);
    137     Interface::free_matrix(X,size);
    138 
    139     Interface::free_matrix(A_ref,size);
    140     Interface::free_matrix(B_ref,size);
    141     Interface::free_matrix(X_ref,size);
    142 
    143     return time;
    144   }
    145 
    146 };
    147 
    148 
    149 #endif
    150 
    151 
    152 
    153