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