| [1726] | 1 | #include "machdefs.h"
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | #include <math.h>
 | 
|---|
| [2322] | 4 | #include <iostream>
 | 
|---|
 | 5 | #include <fstream>
 | 
|---|
| [1726] | 6 | 
 | 
|---|
 | 7 | #include "tarrinit.h"
 | 
|---|
 | 8 | #include "array.h"
 | 
|---|
 | 9 | #include "ctimer.h"
 | 
|---|
 | 10 | #include "timing.h"
 | 
|---|
| [2413] | 11 | #include "srandgen.h"
 | 
|---|
| [1726] | 12 | 
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | // --------------------------------------------------------
 | 
|---|
 | 15 | //  Programme de mesure d'overhead, lie a l'utilisation des
 | 
|---|
 | 16 | //  classes, de NDataBlock et TArray en particulier  
 | 
|---|
 | 17 | //    Attention, l'operateur * declare ds les classes 
 | 
|---|
 | 18 | //  ci-dessous denote l'operation multiplication element 
 | 
|---|
 | 19 | //  par element - Ceci n'est pas le cas pour les Tmatrix<T>
 | 
|---|
 | 20 | // --------------------------------------------------------
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | // --------
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | // ---------------------------------------------------
 | 
|---|
 | 25 | // Classe simple de matrice, utilisant les NDataBlock
 | 
|---|
 | 26 | // ---------------------------------------------------
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | template <class T>
 | 
|---|
 | 29 | class SimpleMatrix : public AnyDataObj {
 | 
|---|
 | 30 | public:
 | 
|---|
 | 31 |                 SimpleMatrix(sa_size_t nr, sa_size_t nc);
 | 
|---|
 | 32 |                 SimpleMatrix(const SimpleMatrix<T> & m);
 | 
|---|
 | 33 |                 SimpleMatrix(const SimpleMatrix<T> & m, bool share);
 | 
|---|
 | 34 |   virtual       ~SimpleMatrix();
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |   virtual SimpleMatrix<T>& Set(const SimpleMatrix<T> & a);
 | 
|---|
 | 37 |   inline SimpleMatrix<T>& operator = (const SimpleMatrix<T> & a)
 | 
|---|
 | 38 |   { return Set(a); }
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |   inline T operator()(int r, int c) const 
 | 
|---|
 | 41 |                 { return data_(r*ncol_+c); }
 | 
|---|
 | 42 |   inline T& operator()(int r, int c) 
 | 
|---|
 | 43 |                 { return data_(r*ncol_+c); }
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 |   inline sa_size_t NRows() const {return nrow_; }
 | 
|---|
 | 46 |   inline sa_size_t NCols() const {return ncol_; }
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 |   SimpleMatrix<T>& AddElt(const SimpleMatrix<T> & b);
 | 
|---|
 | 49 |   SimpleMatrix<T>& MulElt(const SimpleMatrix<T> & b);
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | protected:
 | 
|---|
 | 52 |   sa_size_t ncol_ , nrow_;
 | 
|---|
 | 53 |   NDataBlock<T> data_;
 | 
|---|
 | 54 | };
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | template <class T>
 | 
|---|
 | 57 | inline SimpleMatrix<T> operator + (const SimpleMatrix<T>& a, 
 | 
|---|
 | 58 |                                    const SimpleMatrix<T>& b)
 | 
|---|
 | 59 | {
 | 
|---|
 | 60 |   SimpleMatrix<T> ret(a, false); 
 | 
|---|
 | 61 |   return(ret.AddElt(b));
 | 
|---|
 | 62 | }
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | template <class T>
 | 
|---|
 | 65 | inline SimpleMatrix<T> operator * (const SimpleMatrix<T>& a, 
 | 
|---|
 | 66 |                                    const SimpleMatrix<T>& b)
 | 
|---|
 | 67 | {
 | 
|---|
 | 68 |   SimpleMatrix<T> ret(a, false); 
 | 
|---|
 | 69 |   return(ret.MulElt(b));
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | template <class T>
 | 
|---|
 | 73 | SimpleMatrix<T>::SimpleMatrix(sa_size_t nr, sa_size_t nc)
 | 
|---|
 | 74 |   : nrow_(nr), ncol_(nc), data_(nr*nc) 
 | 
|---|
 | 75 | {
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | template <class T>
 | 
|---|
 | 79 | SimpleMatrix<T>::SimpleMatrix(const SimpleMatrix & m)
 | 
|---|
 | 80 |   : nrow_(m.nrow_), ncol_(m.ncol_), data_(m.data_)
 | 
|---|
 | 81 | {
 | 
|---|
 | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | template <class T>
 | 
|---|
 | 85 | SimpleMatrix<T>::SimpleMatrix(const SimpleMatrix & m, bool share)
 | 
|---|
 | 86 |   : nrow_(m.nrow_), ncol_(m.ncol_), data_(m.data_, share)
 | 
|---|
 | 87 | {
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | template <class T>
 | 
|---|
 | 91 | SimpleMatrix<T>::~SimpleMatrix()
 | 
|---|
 | 92 | {
 | 
|---|
 | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | template <class T>
 | 
|---|
 | 96 | SimpleMatrix<T>& SimpleMatrix<T>::Set(const SimpleMatrix & b)
 | 
|---|
 | 97 | {
 | 
|---|
 | 98 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 99 |     throw(SzMismatchError("SimpleMatrix::Set() Size(a) != Size(b)"));
 | 
|---|
 | 100 |   data_ = b.data_;
 | 
|---|
 | 101 |   return(*this);
 | 
|---|
 | 102 | }
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | template <class T>
 | 
|---|
 | 105 | SimpleMatrix<T>& SimpleMatrix<T>::AddElt(const SimpleMatrix & b)
 | 
|---|
 | 106 | {
 | 
|---|
 | 107 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 108 |     throw(SzMismatchError("SimpleMatrix::AddElt() Size(a) != Size(b)"));
 | 
|---|
 | 109 |   data_ += b.data_;
 | 
|---|
 | 110 |   return(*this);
 | 
|---|
 | 111 | }
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 | template <class T>
 | 
|---|
 | 114 | SimpleMatrix<T>& SimpleMatrix<T>::MulElt(const SimpleMatrix & b)
 | 
|---|
 | 115 | {
 | 
|---|
 | 116 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 117 |     throw(SzMismatchError("SimpleMatrix::MulElt() Size(a) != Size(b)"));
 | 
|---|
 | 118 |   data_ *= b.data_;
 | 
|---|
 | 119 |   return(*this);
 | 
|---|
 | 120 | }
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 | // -------------------------------------------------
 | 
|---|
 | 125 | // Classe simple de matrice nxm , avec new double
 | 
|---|
 | 126 | // -------------------------------------------------
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 | class VerySimpleMatrix {
 | 
|---|
 | 129 | public:
 | 
|---|
 | 130 |                 VerySimpleMatrix(int nr, int nc, bool zero=true);
 | 
|---|
 | 131 |                 VerySimpleMatrix(const VerySimpleMatrix & m);
 | 
|---|
 | 132 |   virtual       ~VerySimpleMatrix();
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 |   virtual VerySimpleMatrix& Set(const VerySimpleMatrix & a);
 | 
|---|
 | 135 |   inline VerySimpleMatrix& operator = (const VerySimpleMatrix & a)
 | 
|---|
 | 136 |   { return Set(a); }
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 |   inline double operator()(int r, int c) const 
 | 
|---|
 | 140 |                 { return a_[r*ncol_+c]; }
 | 
|---|
 | 141 |   inline double& operator()(int r, int c) 
 | 
|---|
 | 142 |                 { return a_[r*ncol_+c]; }
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 |   inline int NRows() const {return nrow_; }
 | 
|---|
 | 145 |   inline int NCols() const {return ncol_; }
 | 
|---|
 | 146 | 
 | 
|---|
 | 147 |   VerySimpleMatrix& AddElt(const VerySimpleMatrix & b);
 | 
|---|
 | 148 |   VerySimpleMatrix& MulElt(const VerySimpleMatrix & b);
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | protected:
 | 
|---|
 | 151 |   int ncol_ , nrow_;
 | 
|---|
 | 152 |   double* a_;
 | 
|---|
 | 153 | };
 | 
|---|
 | 154 | 
 | 
|---|
 | 155 | inline
 | 
|---|
 | 156 | VerySimpleMatrix operator + (const VerySimpleMatrix& a, const VerySimpleMatrix& b)
 | 
|---|
 | 157 | {  
 | 
|---|
 | 158 |   VerySimpleMatrix ret(a);
 | 
|---|
 | 159 |   return(ret.AddElt(b));
 | 
|---|
 | 160 | }
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 | inline
 | 
|---|
 | 163 | VerySimpleMatrix operator * (const VerySimpleMatrix& a, const VerySimpleMatrix& b)
 | 
|---|
 | 164 | {  
 | 
|---|
 | 165 |   VerySimpleMatrix ret(a);
 | 
|---|
 | 166 |   return(ret.MulElt(b));
 | 
|---|
 | 167 | }
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 | VerySimpleMatrix::VerySimpleMatrix(int nr, int nc, bool zero)
 | 
|---|
 | 171 | {
 | 
|---|
 | 172 |   nrow_ = nr; ncol_ = nc;
 | 
|---|
 | 173 |   int l = nrow_ * ncol_;
 | 
|---|
 | 174 |   a_ = new double[l];
 | 
|---|
 | 175 |   if (zero) 
 | 
|---|
 | 176 |     for(int i=0; i<l; i++) a_[i] = 0.;
 | 
|---|
 | 177 | }
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | VerySimpleMatrix::VerySimpleMatrix(const VerySimpleMatrix & m)
 | 
|---|
 | 180 | {
 | 
|---|
 | 181 |   nrow_ = m.nrow_; ncol_ = m.ncol_;
 | 
|---|
 | 182 |   a_ = new double[nrow_ * ncol_];
 | 
|---|
 | 183 |   for(int i=0; i<nrow_ * ncol_; i++)
 | 
|---|
 | 184 |     a_[i] = m.a_[i];
 | 
|---|
 | 185 | }
 | 
|---|
 | 186 | 
 | 
|---|
 | 187 | VerySimpleMatrix::~VerySimpleMatrix()
 | 
|---|
 | 188 | {
 | 
|---|
 | 189 |   delete[] a_;
 | 
|---|
 | 190 | }
 | 
|---|
 | 191 | 
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 | VerySimpleMatrix& VerySimpleMatrix::Set(const VerySimpleMatrix & b)
 | 
|---|
 | 194 | {
 | 
|---|
 | 195 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 196 |     throw(SzMismatchError("VerySimpleMatrix::Set Size(a) != Size(b)"));
 | 
|---|
 | 197 |   for(int i=0; i<nrow_ * ncol_; i++)
 | 
|---|
 | 198 |     a_[i] = b.a_[i];
 | 
|---|
 | 199 |   return(*this);
 | 
|---|
 | 200 | }
 | 
|---|
 | 201 | 
 | 
|---|
 | 202 | VerySimpleMatrix& VerySimpleMatrix::AddElt(const VerySimpleMatrix & b)
 | 
|---|
 | 203 | {
 | 
|---|
 | 204 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 205 |     throw(SzMismatchError("VerySimpleMatrix::AddElt() Size(a) != Size(b)"));
 | 
|---|
 | 206 |   for(int i=0; i<nrow_ * ncol_; i++)
 | 
|---|
 | 207 |     a_[i] += b.a_[i];
 | 
|---|
 | 208 |   return(*this);
 | 
|---|
 | 209 | }
 | 
|---|
 | 210 | 
 | 
|---|
 | 211 | VerySimpleMatrix& VerySimpleMatrix::MulElt(const VerySimpleMatrix & b)
 | 
|---|
 | 212 | {
 | 
|---|
 | 213 |   if ((nrow_ != b.nrow_) || (ncol_ != b.ncol_))
 | 
|---|
 | 214 |     throw(SzMismatchError("VerySimpleMatrix::MulElt() Size(a) != Size(b)"));
 | 
|---|
 | 215 |   for(int i=0; i<nrow_ * ncol_; i++)
 | 
|---|
 | 216 |     a_[i] += b.a_[i];
 | 
|---|
 | 217 |   return(*this);
 | 
|---|
 | 218 | }
 | 
|---|
 | 219 | 
 | 
|---|
 | 220 | 
 | 
|---|
 | 221 | //--------------------------------------------------------
 | 
|---|
 | 222 | // classe template de matrice NxM 
 | 
|---|
 | 223 | //--------------------------------------------------------
 | 
|---|
 | 224 | 
 | 
|---|
 | 225 | template <class T, int L, int C> 
 | 
|---|
 | 226 | class SmallMatrix {
 | 
|---|
 | 227 | public:
 | 
|---|
 | 228 |                 SmallMatrix() { } 
 | 
|---|
 | 229 |                 SmallMatrix(const SmallMatrix<T,L,C> & m)
 | 
|---|
 | 230 |                    { for(int i=0; i<L*C; i++)  data_[i] = m.data_[i]; }
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 |   virtual       ~SmallMatrix() { }
 | 
|---|
 | 233 | 
 | 
|---|
 | 234 |   inline SmallMatrix<T,L,C>& Set(const SmallMatrix<T,L,C> & m)
 | 
|---|
 | 235 |                    { for(int i=0; i<L*C; i++) data_[i] = m.data_[i]; return (*this); }
 | 
|---|
 | 236 |   inline SmallMatrix<T,L,C>& operator = (const SmallMatrix<T,L,C>& a)
 | 
|---|
 | 237 |                  { return Set(a); } 
 | 
|---|
 | 238 |  
 | 
|---|
 | 239 | 
 | 
|---|
 | 240 | 
 | 
|---|
 | 241 |   inline T operator()(int r, int c) const 
 | 
|---|
 | 242 |                 { return data_[r*C+c]; }
 | 
|---|
 | 243 |   inline T& operator()(int r, int c) 
 | 
|---|
 | 244 |                 { return data_[r*C+c]; }
 | 
|---|
 | 245 | 
 | 
|---|
 | 246 |   inline int NRows() const {return L; }
 | 
|---|
 | 247 |   inline int NCols() const {return C; }
 | 
|---|
 | 248 | 
 | 
|---|
 | 249 |   inline SmallMatrix<T,L,C> & AddElt(const SmallMatrix<T,L,C> & m)
 | 
|---|
 | 250 |                    { for(int i=0; i<L*C; i++) data_[i] += m.data_[i]; return (*this); }
 | 
|---|
 | 251 | 
 | 
|---|
 | 252 |   inline SmallMatrix<T,L,C> & MulElt(const SmallMatrix<T,L,C> & m)
 | 
|---|
 | 253 |                    { for(int i=0; i<L*C; i++) data_[i] *= m.data_[i]; return (*this); }
 | 
|---|
 | 254 | 
 | 
|---|
 | 255 | protected:
 | 
|---|
 | 256 |   T data_[L*C];
 | 
|---|
 | 257 | };
 | 
|---|
 | 258 | 
 | 
|---|
 | 259 | template <class T, int L, int C> 
 | 
|---|
 | 260 | inline SmallMatrix<T,L,C> 
 | 
|---|
 | 261 |        operator + (const SmallMatrix<T,L,C>& a, const SmallMatrix<T,L,C>& b)
 | 
|---|
 | 262 |    {  SmallMatrix<T,L,C> ret(a);  return(ret.AddElt(b)); }
 | 
|---|
 | 263 | 
 | 
|---|
 | 264 | template <class T, int L, int C> 
 | 
|---|
 | 265 | inline SmallMatrix<T,L,C> 
 | 
|---|
 | 266 |        operator * (const SmallMatrix<T,L,C>& a, const SmallMatrix<T,L,C>& b)
 | 
|---|
 | 267 |    {  SmallMatrix<T,L,C> ret(a);  return(ret.MulElt(b)); }
 | 
|---|
 | 268 | 
 | 
|---|
 | 269 |  
 | 
|---|
 | 270 | // -------------------------------------------------------
 | 
|---|
 | 271 | // Classe simple de matrice 2x2 - sans allocation memoire
 | 
|---|
 | 272 | // -------------------------------------------------------
 | 
|---|
 | 273 | 
 | 
|---|
 | 274 | class VerySimpleMatrix2x2 {
 | 
|---|
 | 275 | public:
 | 
|---|
 | 276 |   inline        VerySimpleMatrix2x2() { } 
 | 
|---|
 | 277 |   inline        VerySimpleMatrix2x2(const VerySimpleMatrix2x2 & m)
 | 
|---|
 | 278 |                    { for(int i=0; i<4; i++)  a_[i] = m.a_[i]; }
 | 
|---|
 | 279 | 
 | 
|---|
 | 280 |   inline        ~VerySimpleMatrix2x2() { }
 | 
|---|
 | 281 | 
 | 
|---|
 | 282 |   inline VerySimpleMatrix2x2& Set(const VerySimpleMatrix2x2 & m)
 | 
|---|
 | 283 |                    { for(int i=0; i<4; i++) a_[i] = m.a_[i]; return (*this); }
 | 
|---|
 | 284 |   inline VerySimpleMatrix2x2& operator = (const VerySimpleMatrix2x2 & a)
 | 
|---|
 | 285 |                    { return Set(a); }
 | 
|---|
 | 286 | 
 | 
|---|
 | 287 |   inline double operator()(int r, int c) const 
 | 
|---|
 | 288 |                 { return a_[r*2+c]; }
 | 
|---|
 | 289 |   inline double& operator()(int r, int c) 
 | 
|---|
 | 290 |                 { return a_[r*2+c]; }
 | 
|---|
 | 291 | 
 | 
|---|
 | 292 |   inline int NRows() const {return 2; }
 | 
|---|
 | 293 |   inline int NCols() const {return 2; }
 | 
|---|
 | 294 | 
 | 
|---|
 | 295 |   inline VerySimpleMatrix2x2& AddElt(const VerySimpleMatrix2x2 & m)
 | 
|---|
 | 296 |                    { for(int i=0; i<4; i++) a_[i] += m.a_[i]; return (*this); }
 | 
|---|
 | 297 |   inline VerySimpleMatrix2x2& MulElt(const VerySimpleMatrix2x2 & m)
 | 
|---|
 | 298 |                    { for(int i=0; i<4; i++) a_[i] *= m.a_[i]; return (*this); }
 | 
|---|
 | 299 | 
 | 
|---|
 | 300 | protected:
 | 
|---|
 | 301 |   double a_[4];
 | 
|---|
 | 302 | };
 | 
|---|
 | 303 | 
 | 
|---|
 | 304 | inline VerySimpleMatrix2x2 operator + (const VerySimpleMatrix2x2& a, const VerySimpleMatrix2x2& b)
 | 
|---|
 | 305 |    {  VerySimpleMatrix2x2 ret(a);  return(ret.AddElt(b)); }
 | 
|---|
 | 306 | 
 | 
|---|
 | 307 | inline VerySimpleMatrix2x2 operator * (const VerySimpleMatrix2x2& a, const VerySimpleMatrix2x2& b)
 | 
|---|
 | 308 |    {  VerySimpleMatrix2x2 ret(a);  return(ret.MulElt(b)); }
 | 
|---|
 | 309 | 
 | 
|---|
 | 310 | // ------------------------------------------------------------
 | 
|---|
 | 311 | //   programme de test 
 | 
|---|
 | 312 | //   Appel: ovharr NLoop [NRow NCol]
 | 
|---|
 | 313 | //   NRow = 0 ou NCol = 0 --> test 2x2 only  
 | 
|---|
 | 314 | // ------------------------------------------------------------ 
 | 
|---|
 | 315 | 
 | 
|---|
 | 316 | void add_double_n(int n, double* x1, double* x2, double* x3);
 | 
|---|
 | 317 | void mul_double_n(int n, double* x1, double* x2, double* x3);
 | 
|---|
 | 318 | 
 | 
|---|
 | 319 | int main(int narg, char* arg[])
 | 
|---|
 | 320 | {
 | 
|---|
 | 321 | 
 | 
|---|
 | 322 |   SophyaInit();
 | 
|---|
 | 323 |   InitTim();   // Initializing the CPU timer
 | 
|---|
 | 324 | 
 | 
|---|
 | 325 |   if (narg < 2) {
 | 
|---|
 | 326 |     cout << " Missing argument/ Usage: ovharr NLoop [NRow NCol] \n " 
 | 
|---|
 | 327 |          << " NRow==0 OR NCol==0   ---> Test 2x2 only \n " << endl;
 | 
|---|
 | 328 |     exit(1);
 | 
|---|
 | 329 |   }
 | 
|---|
 | 330 |   int i,j,k;
 | 
|---|
 | 331 |   char buff[128];
 | 
|---|
 | 332 |   int N = atoi(arg[1]);
 | 
|---|
 | 333 |   int nrow = 2; 
 | 
|---|
 | 334 |   int ncol = 2;
 | 
|---|
 | 335 | 
 | 
|---|
 | 336 |   if (narg > 2)  nrow = atoi(arg[2]);
 | 
|---|
 | 337 |   if (narg > 3)  ncol = atoi(arg[3]);
 | 
|---|
 | 338 | 
 | 
|---|
 | 339 |   bool fgall = true;
 | 
|---|
 | 340 |   if ((nrow == 0) || (ncol == 0))    fgall = false;
 | 
|---|
 | 341 | 
 | 
|---|
 | 342 |   cout << " ovharr/ Testing TArray overhead - NLoop = " << N 
 | 
|---|
 | 343 |        << "  NRow=" << nrow << " NCol= " << ncol << endl;
 | 
|---|
 | 344 |   try {
 | 
|---|
 | 345 | 
 | 
|---|
 | 346 |     if (fgall) {
 | 
|---|
 | 347 |       cout << "1) ------ Overhead using TMatrix<T> ------" << endl;
 | 
|---|
 | 348 |       Timer tm("Overhead:TMatrix<T>");
 | 
|---|
 | 349 |       for(k=0; k<N; k++) {
 | 
|---|
 | 350 |         Matrix * m1 = new Matrix(nrow, ncol);
 | 
|---|
 | 351 |         Matrix * m2 = new Matrix(nrow, ncol);
 | 
|---|
 | 352 |         Matrix * m3 = new Matrix(nrow, ncol);
 | 
|---|
 | 353 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 354 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 355 |             (*m1)(i,j) = k*300+10.*i+j; 
 | 
|---|
 | 356 |             (*m2)(i,j) = k*550+20.*i+2.*j;      
 | 
|---|
 | 357 |           }
 | 
|---|
 | 358 |         *m3 = *m1 + *m2;
 | 
|---|
 | 359 |         // m4 = m1*m2 est une multiplication de matrice avec les TMatrix<T>
 | 
|---|
 | 360 |         Matrix * m4 = new Matrix(*m1);
 | 
|---|
 | 361 |         m4->MulElt(*m2);  
 | 
|---|
 | 362 | 
 | 
|---|
 | 363 |         delete m1; 
 | 
|---|
 | 364 |         delete m2; 
 | 
|---|
 | 365 |         delete m3;
 | 
|---|
 | 366 |         delete m4;
 | 
|---|
 | 367 |       //  if (k%(N/10) == 0) {
 | 
|---|
 | 368 |       //    sprintf(buff, "ovharr: Iteration k= %d ",k);
 | 
|---|
 | 369 |       //    PrtTim(buff);
 | 
|---|
 | 370 |       //  }
 | 
|---|
 | 371 |       }
 | 
|---|
 | 372 |     }
 | 
|---|
 | 373 | 
 | 
|---|
 | 374 |     if (fgall) {
 | 
|---|
 | 375 |       cout << "2) ------ Overhead using TMatrix<T> No new ------" << endl;
 | 
|---|
 | 376 |       Timer tm("Overhead:TMatrix<T> No new");
 | 
|---|
 | 377 |       for(k=0; k<N; k++) {
 | 
|---|
 | 378 |         Matrix m1(nrow, ncol);
 | 
|---|
 | 379 |         Matrix m2(nrow, ncol);
 | 
|---|
 | 380 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 381 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 382 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 383 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 384 |           }
 | 
|---|
 | 385 |         Matrix m3 = m1 + m2;
 | 
|---|
 | 386 |         Matrix m4(m1);
 | 
|---|
 | 387 |         m4.MulElt(m2); 
 | 
|---|
 | 388 |       }
 | 
|---|
 | 389 |     }
 | 
|---|
 | 390 | 
 | 
|---|
 | 391 |     if (fgall) {
 | 
|---|
 | 392 |       cout << "3) ------ Overhead using SimpleMatrix<r_8> ------" << endl;
 | 
|---|
 | 393 |       Timer tm("Overhead:SimpleMatrix<r_8>");
 | 
|---|
 | 394 |       for(k=0; k<N; k++) {
 | 
|---|
 | 395 |         SimpleMatrix<r_8> * m1 = new SimpleMatrix<r_8>(nrow, ncol);
 | 
|---|
 | 396 |         SimpleMatrix<r_8> * m2 = new SimpleMatrix<r_8>(nrow, ncol);
 | 
|---|
 | 397 |         SimpleMatrix<r_8> * m3 = new SimpleMatrix<r_8>(nrow, ncol);
 | 
|---|
 | 398 |         SimpleMatrix<r_8> * m4 = new SimpleMatrix<r_8>(nrow, ncol);
 | 
|---|
 | 399 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 400 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 401 |             (*m1)(i,j) = k*300+10.*i+j; 
 | 
|---|
 | 402 |             (*m2)(i,j) = k*550+20.*i+2.*j;      
 | 
|---|
 | 403 |           }
 | 
|---|
 | 404 |         *m3 = *m1 + *m2;
 | 
|---|
 | 405 |         *m4 = *m1 * *m2;
 | 
|---|
 | 406 |         delete m1; 
 | 
|---|
 | 407 |         delete m2; 
 | 
|---|
 | 408 |         delete m3;
 | 
|---|
 | 409 |         delete m4;
 | 
|---|
 | 410 |       }
 | 
|---|
 | 411 |     }
 | 
|---|
 | 412 | 
 | 
|---|
 | 413 |     if (fgall) {
 | 
|---|
 | 414 |       cout << "4) ---- Overhead using SimpleMatrix<r_8> NO new ----" << endl;
 | 
|---|
 | 415 |       Timer tm("Overhead:SimpleMatrix<r_8> NO new");
 | 
|---|
 | 416 |       for(k=0; k<N; k++) {
 | 
|---|
 | 417 |         SimpleMatrix<r_8> m1(nrow, ncol);
 | 
|---|
 | 418 |         SimpleMatrix<r_8> m2(nrow, ncol);
 | 
|---|
 | 419 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 420 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 421 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 422 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 423 |           }
 | 
|---|
 | 424 |         SimpleMatrix<r_8> m3 = m1 + m2;
 | 
|---|
 | 425 |         SimpleMatrix<r_8> m4 = m1 * m2;
 | 
|---|
 | 426 |       }
 | 
|---|
 | 427 |     }
 | 
|---|
 | 428 | 
 | 
|---|
 | 429 |     if (fgall) {
 | 
|---|
 | 430 |       cout << "5) ---- Overhead using VerySimpleMatrix( , , zero=true) ----" << endl;
 | 
|---|
 | 431 |       Timer tm("Overhead:VerySimpleMatrix( , , zero=true)");
 | 
|---|
 | 432 |       for(k=0; k<N; k++) {
 | 
|---|
 | 433 |         VerySimpleMatrix * m1 = new VerySimpleMatrix(nrow, ncol, true);
 | 
|---|
 | 434 |         VerySimpleMatrix * m2 = new VerySimpleMatrix(nrow, ncol, true);
 | 
|---|
 | 435 |         VerySimpleMatrix * m3 = new VerySimpleMatrix(nrow, ncol, true);
 | 
|---|
 | 436 |         VerySimpleMatrix * m4 = new VerySimpleMatrix(nrow, ncol, true);
 | 
|---|
 | 437 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 438 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 439 |             (*m1)(i,j) = k*300+10.*i+j; 
 | 
|---|
 | 440 |             (*m2)(i,j) = k*550+20.*i+2.*j;      
 | 
|---|
 | 441 |           }
 | 
|---|
 | 442 |         *m3 = *m1 + *m2;
 | 
|---|
 | 443 |         *m4 = *m1 * *m2;
 | 
|---|
 | 444 |         delete m1; 
 | 
|---|
 | 445 |         delete m2; 
 | 
|---|
 | 446 |         delete m3;
 | 
|---|
 | 447 |         delete m4;
 | 
|---|
 | 448 |       }
 | 
|---|
 | 449 |     }
 | 
|---|
 | 450 | 
 | 
|---|
 | 451 |     if (fgall) {
 | 
|---|
 | 452 |       cout << "6) ---- Overhead using VerySimpleMatrix( , , zero=false) ----" << endl;
 | 
|---|
 | 453 |       Timer tm("Overhead:VerySimpleMatrix( , , zero=true)");
 | 
|---|
 | 454 |       for(k=0; k<N; k++) {
 | 
|---|
 | 455 |         VerySimpleMatrix * m1 = new VerySimpleMatrix(nrow, ncol, false);
 | 
|---|
 | 456 |         VerySimpleMatrix * m2 = new VerySimpleMatrix(nrow, ncol, false);
 | 
|---|
 | 457 |         VerySimpleMatrix * m3 = new VerySimpleMatrix(nrow, ncol, false);
 | 
|---|
 | 458 |         VerySimpleMatrix * m4 = new VerySimpleMatrix(nrow, ncol, false);
 | 
|---|
 | 459 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 460 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 461 |             (*m1)(i,j) = k*300+10.*i+j; 
 | 
|---|
 | 462 |             (*m2)(i,j) = k*550+20.*i+2.*j;      
 | 
|---|
 | 463 |           }
 | 
|---|
 | 464 |         *m3 = *m1 + *m2;
 | 
|---|
 | 465 |         *m4 = *m1 * *m2;
 | 
|---|
 | 466 |         delete m1; 
 | 
|---|
 | 467 |         delete m2; 
 | 
|---|
 | 468 |         delete m3;
 | 
|---|
 | 469 |         delete m4;
 | 
|---|
 | 470 |       }
 | 
|---|
 | 471 |     }
 | 
|---|
 | 472 | 
 | 
|---|
 | 473 |     if (fgall) {
 | 
|---|
 | 474 |       cout << "7) ---- Overhead using VerySimpleMatrix( , , zero=false) NO new ----" << endl;
 | 
|---|
 | 475 |       Timer tm("Overhead:VerySimpleMatrix( , , zero=true) NO new");
 | 
|---|
 | 476 |       for(k=0; k<N; k++) {
 | 
|---|
 | 477 |         VerySimpleMatrix m1(nrow, ncol, false);
 | 
|---|
 | 478 |         VerySimpleMatrix m2(nrow, ncol, false);
 | 
|---|
 | 479 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 480 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 481 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 482 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 483 |           }
 | 
|---|
 | 484 |         VerySimpleMatrix m3 = m1 + m2;
 | 
|---|
 | 485 |         VerySimpleMatrix m4 = m1 * m2;
 | 
|---|
 | 486 |       }
 | 
|---|
 | 487 |     }
 | 
|---|
 | 488 | 
 | 
|---|
 | 489 |     if (fgall) {
 | 
|---|
 | 490 |       cout << "8) ---- Overhead using new double[nrow*ncol] ----" << endl;
 | 
|---|
 | 491 |       Timer tm("Overhead:new double[nrow*ncol]");
 | 
|---|
 | 492 |       for(k=0; k<N; k++) {
 | 
|---|
 | 493 |         int l = nrow*ncol;
 | 
|---|
 | 494 |         double* m1 = new double[l];
 | 
|---|
 | 495 |         double* m2 = new double[l];
 | 
|---|
 | 496 |         double* m3 = new double[l];
 | 
|---|
 | 497 |         double* m4 = new double[l];
 | 
|---|
 | 498 |         for(i=0; i<nrow; i++)
 | 
|---|
 | 499 |           for(j=0; j<ncol; j++) {
 | 
|---|
 | 500 |             m1[i*ncol+j] = k*300+10.*i+j;       
 | 
|---|
 | 501 |             m2[i*ncol+j] = k*550+20.*i+2.*j;    
 | 
|---|
 | 502 |           }
 | 
|---|
 | 503 |         for(i=0; i<l; i++) m3[i] = m1[i] + m2[i];
 | 
|---|
 | 504 |         for(i=0; i<l; i++) m3[i] = m4[i] * m2[i];
 | 
|---|
 | 505 |         delete[] m1; 
 | 
|---|
 | 506 |         delete[] m2; 
 | 
|---|
 | 507 |         delete[] m3;
 | 
|---|
 | 508 |         delete[] m4;
 | 
|---|
 | 509 |       }
 | 
|---|
 | 510 |     }
 | 
|---|
 | 511 | 
 | 
|---|
 | 512 | 
 | 
|---|
 | 513 |     {
 | 
|---|
 | 514 |       cout << "9) ---- Overhead using SmallMatrix<r_8,4,5> No new ----" << endl;
 | 
|---|
 | 515 |       Timer tm("Overhead:SmallMatrix<r_8,4,5> No new ");
 | 
|---|
 | 516 |       for(k=0; k<N; k++) {
 | 
|---|
 | 517 |         SmallMatrix<r_8,4,5> m1,m2;
 | 
|---|
 | 518 |         for(i=0; i<4; i++)
 | 
|---|
 | 519 |           for(j=0; j<5; j++) {
 | 
|---|
 | 520 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 521 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 522 |           }
 | 
|---|
 | 523 |         SmallMatrix<r_8,4,5> m3 = m1 + m2;
 | 
|---|
 | 524 |         SmallMatrix<r_8,4,5> m4 = m1 * m2;
 | 
|---|
 | 525 |       }
 | 
|---|
 | 526 |     }
 | 
|---|
 | 527 | 
 | 
|---|
 | 528 |     {
 | 
|---|
 | 529 |       cout << "10) ---- Overhead using SmallMatrix<r_8,2,2> No new ----" << endl;
 | 
|---|
 | 530 |       Timer tm("Overhead:SmallMatrix<r_8,2,2> No new");
 | 
|---|
 | 531 |       for(k=0; k<N; k++) {
 | 
|---|
 | 532 |         SmallMatrix<r_8,2,2> m1,m2;
 | 
|---|
 | 533 |         for(i=0; i<2; i++)
 | 
|---|
 | 534 |           for(j=0; j<2; j++) {
 | 
|---|
 | 535 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 536 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 537 |           }
 | 
|---|
 | 538 |         SmallMatrix<r_8,2,2>m3 = m1 + m2;
 | 
|---|
 | 539 |         SmallMatrix<r_8,2,2>m4 = m1 * m2;
 | 
|---|
 | 540 |      }
 | 
|---|
 | 541 |     }
 | 
|---|
 | 542 | 
 | 
|---|
 | 543 | 
 | 
|---|
 | 544 |     {
 | 
|---|
 | 545 |       cout << "11) ---- Overhead using VerySimpleMatrix2x2 ----" << endl;
 | 
|---|
 | 546 |       Timer tm("Overhead:VerySimpleMatrix2x2");
 | 
|---|
 | 547 |       for(k=0; k<N; k++) {
 | 
|---|
 | 548 |         VerySimpleMatrix2x2 * m1 = new VerySimpleMatrix2x2();
 | 
|---|
 | 549 |         VerySimpleMatrix2x2 * m2 = new VerySimpleMatrix2x2();
 | 
|---|
 | 550 |         VerySimpleMatrix2x2 * m3 = new VerySimpleMatrix2x2();
 | 
|---|
 | 551 |         VerySimpleMatrix2x2 * m4 = new VerySimpleMatrix2x2();
 | 
|---|
 | 552 |         for(i=0; i<2; i++)
 | 
|---|
 | 553 |           for(j=0; j<2; j++) {
 | 
|---|
 | 554 |             (*m1)(i,j) = k*300+10.*i+j; 
 | 
|---|
 | 555 |             (*m2)(i,j) = k*550+20.*i+2.*j;      
 | 
|---|
 | 556 |           }
 | 
|---|
 | 557 |         *m3 = *m1 + *m2;
 | 
|---|
 | 558 |         *m4 = *m1 * *m2;
 | 
|---|
 | 559 |         delete m1; 
 | 
|---|
 | 560 |         delete m2; 
 | 
|---|
 | 561 |         delete m3;
 | 
|---|
 | 562 |         delete m4;
 | 
|---|
 | 563 |       }
 | 
|---|
 | 564 |     }
 | 
|---|
 | 565 | 
 | 
|---|
 | 566 |     {
 | 
|---|
 | 567 |       cout << "12) ---- Overhead using VerySimpleMatrix2x2 NO new ----" << endl;
 | 
|---|
 | 568 |       Timer tm("Overhead:VerySimpleMatrix2x2 NO new");
 | 
|---|
 | 569 |       for(k=0; k<N; k++) {
 | 
|---|
 | 570 |         VerySimpleMatrix2x2 m1,m2;
 | 
|---|
 | 571 |         for(i=0; i<2; i++)
 | 
|---|
 | 572 |           for(j=0; j<2; j++) {
 | 
|---|
 | 573 |             m1(i,j) = k*300+10.*i+j;    
 | 
|---|
 | 574 |             m2(i,j) = k*550+20.*i+2.*j; 
 | 
|---|
 | 575 |           }
 | 
|---|
 | 576 |         VerySimpleMatrix2x2 m3 = m1+m2;
 | 
|---|
 | 577 |         VerySimpleMatrix2x2 m4 = m1*m2;
 | 
|---|
 | 578 |       }
 | 
|---|
 | 579 |     }
 | 
|---|
 | 580 | 
 | 
|---|
 | 581 | 
 | 
|---|
 | 582 |     {
 | 
|---|
 | 583 |       cout << "13) ---- Overhead using double a[4] + function call ----" << endl;
 | 
|---|
 | 584 |       Timer tm("Overhead:double a[4]");
 | 
|---|
 | 585 |       for(k=0; k<N; k++) {
 | 
|---|
 | 586 |         double m1[4], m2[4], m3[4], m4[4];
 | 
|---|
 | 587 |         for(i=0; i<2; i++)
 | 
|---|
 | 588 |           for(j=0; j<2; j++) {
 | 
|---|
 | 589 |             m1[i*2+j] = k*300+10.*i+j;  
 | 
|---|
 | 590 |             m2[i*2+j] = k*550+20.*i+2.*j;       
 | 
|---|
 | 591 |           }
 | 
|---|
 | 592 |         add_double_n(4, m1, m2, m3);
 | 
|---|
 | 593 |         mul_double_n(4, m1, m2, m4);
 | 
|---|
 | 594 |       }
 | 
|---|
 | 595 |     }
 | 
|---|
 | 596 | 
 | 
|---|
 | 597 |     {
 | 
|---|
 | 598 |       cout << "14) ---- Overhead a3[4] = a1[4]+a2[4] ----" << endl;
 | 
|---|
 | 599 |       Timer tm("Overhead:double a[4]");
 | 
|---|
 | 600 |       for(k=0; k<N; k++) {
 | 
|---|
 | 601 |         double m1[4], m2[4], m3[4], m4[4];
 | 
|---|
 | 602 |         for(i=0; i<2; i++)
 | 
|---|
 | 603 |           for(j=0; j<2; j++) {
 | 
|---|
 | 604 |             m1[i*2+j] = k*300+10.*i+j;  
 | 
|---|
 | 605 |             m2[i*2+j] = k*550+20.*i+2.*j;       
 | 
|---|
 | 606 |           }
 | 
|---|
 | 607 |         for(i=0; i<4; i++) m3[i] = m1[i] + m2[i];
 | 
|---|
 | 608 |         for(i=0; i<4; i++) m4[i] = m1[i] * m2[i];
 | 
|---|
 | 609 |       }
 | 
|---|
 | 610 |     }
 | 
|---|
 | 611 | 
 | 
|---|
 | 612 | 
 | 
|---|
 | 613 |   }
 | 
|---|
 | 614 |   catch (PThrowable exc) {
 | 
|---|
 | 615 |     cerr << " catched Exception " << exc.Msg() << endl;
 | 
|---|
 | 616 |   }  
 | 
|---|
 | 617 |   catch (...) {
 | 
|---|
 | 618 |     cerr << " catched unknown (...) exception " << endl; 
 | 
|---|
 | 619 |   }  
 | 
|---|
 | 620 | 
 | 
|---|
 | 621 |   cout << "\n --------------------------------------------------------" << endl;
 | 
|---|
 | 622 |   PrtTim("--- End of ovharr ---");
 | 
|---|
 | 623 |   cout << " ---------------  END of ovharr programme -------------- " << endl;
 | 
|---|
 | 624 | }
 | 
|---|
 | 625 | 
 | 
|---|
 | 626 | /* Fonction pour ajouter deux tableaux */
 | 
|---|
 | 627 | void add_double_n(int n, double* x1, double* x2, double* x3)
 | 
|---|
 | 628 | {
 | 
|---|
 | 629 |   if (n < 1) 
 | 
|---|
 | 630 |     throw(SzMismatchError("add_double_n : n<1 !"));
 | 
|---|
 | 631 |   for(int i=0; i<n; i++) x3[i] = x1[i] + x2[i];
 | 
|---|
 | 632 |   return;
 | 
|---|
 | 633 | }
 | 
|---|
 | 634 | /* Fonction pour multiplier deux tableaux */
 | 
|---|
 | 635 | void mul_double_n(int n, double* x1, double* x2, double* x3)
 | 
|---|
 | 636 | {
 | 
|---|
 | 637 |   if (n < 1) 
 | 
|---|
 | 638 |     throw(SzMismatchError("mul_double_n : n<1 !"));
 | 
|---|
 | 639 |   for(int i=0; i<n; i++) x3[i] = x1[i] * x2[i];
 | 
|---|
 | 640 |   return;
 | 
|---|
 | 641 | }
 | 
|---|