action_matrix_matrix_product_bis.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  action_matrix_matrix_product_bis.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>
00004 // Copyright (C) EDF R&D,  lun sep 30 14:23:19 CEST 2002
00005 //=====================================================
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 //
00020 #ifndef ACTION_MATRIX_MATRIX_PRODUCT_BIS
00021 #define ACTION_MATRIX_MATRIX_PRODUCT_BIS
00022 #include "utilities.h"
00023 #include "STL_interface.hh"
00024 #include "STL_timer.hh"
00025 #include <string>
00026 #include "init_function.hh"
00027 #include "init_vector.hh"
00028 #include "init_matrix.hh"
00029 
00030 using namespace std;
00031 
00032 template<class Interface>
00033 class Action_matrix_matrix_product_bis {
00034 
00035 public :
00036 
00037   static inline std::string name( void )
00038   {
00039     return "matrix_matrix_"+Interface::name();
00040   }
00041 
00042   static double nb_op_base(int size){
00043     return 2.0*size*size*size;
00044   }
00045 
00046   static double calculate( int nb_calc, int size ) {
00047 
00048     // STL matrix and vector initialization
00049 
00050     typename Interface::stl_matrix A_stl;
00051     typename Interface::stl_matrix B_stl;
00052     typename Interface::stl_matrix X_stl;
00053 
00054     init_matrix<pseudo_random>(A_stl,size);
00055     init_matrix<pseudo_random>(B_stl,size);
00056     init_matrix<null_function>(X_stl,size);
00057 
00058     // generic matrix and vector initialization
00059 
00060     typename Interface::gene_matrix A_ref;
00061     typename Interface::gene_matrix B_ref;
00062     typename Interface::gene_matrix X_ref;
00063 
00064     typename Interface::gene_matrix A;
00065     typename Interface::gene_matrix B;
00066     typename Interface::gene_matrix X;
00067 
00068 
00069     Interface::matrix_from_stl(A_ref,A_stl);
00070     Interface::matrix_from_stl(B_ref,B_stl);
00071     Interface::matrix_from_stl(X_ref,X_stl);
00072 
00073     Interface::matrix_from_stl(A,A_stl);
00074     Interface::matrix_from_stl(B,B_stl);
00075     Interface::matrix_from_stl(X,X_stl);
00076 
00077 
00078     // STL_timer utilities
00079 
00080     STL_timer chronos;
00081 
00082     // Baseline evaluation
00083 
00084     chronos.start_baseline(nb_calc);
00085 
00086     do {
00087 
00088       Interface::copy_matrix(A_ref,A,size);
00089       Interface::copy_matrix(B_ref,B,size);
00090       Interface::copy_matrix(X_ref,X,size);
00091 
00092 
00093       //      Interface::matrix_matrix_product(A,B,X,size); This line must be commented !!!!
00094     }
00095     while(chronos.check());
00096 
00097     chronos.report(true);
00098 
00099     // Time measurement
00100 
00101     chronos.start(nb_calc);
00102 
00103     do {
00104 
00105       Interface::copy_matrix(A_ref,A,size);
00106       Interface::copy_matrix(B_ref,B,size);
00107       Interface::copy_matrix(X_ref,X,size);
00108 
00109       Interface::matrix_matrix_product(A,B,X,size); // here it is not commented !!!!
00110     }
00111     while(chronos.check());
00112 
00113     chronos.report(true);
00114 
00115     double time=chronos.calculated_time/2000.0;
00116 
00117     // calculation check
00118 
00119     typename Interface::stl_matrix resu_stl(size);
00120 
00121     Interface::matrix_to_stl(X,resu_stl);
00122 
00123     STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,size);
00124 
00125     typename Interface::real_type error=
00126       STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl);
00127 
00128     if (error>1.e-6){
00129       INFOS("WRONG CALCULATION...residual=" << error);
00130       exit(1);
00131     }
00132 
00133     // deallocation and return time
00134 
00135     Interface::free_matrix(A,size);
00136     Interface::free_matrix(B,size);
00137     Interface::free_matrix(X,size);
00138 
00139     Interface::free_matrix(A_ref,size);
00140     Interface::free_matrix(B_ref,size);
00141     Interface::free_matrix(X_ref,size);
00142 
00143     return time;
00144   }
00145 
00146 };
00147 
00148 
00149 #endif
00150 
00151 
00152 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:42