source: Sophya/trunk/Eval/JET/tjet.cc@ 4054

Last change on this file since 4054 was 4054, checked in by ansari, 14 years ago

ajout programme telacc.cc pour test rapidite acces aux elements, Reza 17/03/2012

File size: 7.3 KB
Line 
1#include "machdefs.h"
2
3#include <math.h>
4#include <iostream>
5#include <fstream>
6
7#include "tarrinit.h"
8#include "array.h"
9
10#include "pexceptions.h"
11#include "srandgen.h"
12
13#include "sophyainit.h"
14#include "ctimer.h"
15#include "timing.h"
16
17#include "smtx.h"
18
19//--------------------------------------------------------
20// Test d'expression template sur tableaux
21// Reza - Avril 2003
22// revisite : Mars 2012
23//--------------------------------------------------------
24
25//------- Le code de smtx.cc
26
27#include "smtx.cc"
28
29//-------
30// ------------------------------------------------
31// programme de test template expressions
32// ------------------------------------------------
33
34int main(int narg, char* arg[])
35{
36
37 SophyaInit();
38 InitTim(); // Initializing the CPU timer
39
40 if (narg < 3) {
41 cout << "\n te/ TemplateExpression Test - missing arguments\n"
42 << " Usage: te NLoop NRow NCol \n" << endl;
43 return 1;
44 }
45 int N = 10;
46 int nrow = 2;
47 int ncol = 2;
48
49 N = atoi(arg[1]);
50
51 nrow = atoi(arg[2]);
52 ncol = atoi(arg[3]);
53
54 cout << " te/ TemplateExpression Test - NLoop = " << N
55 << " NRow=" << nrow << " NCol= " << ncol
56 << " Size=nr*nc= " << nrow*ncol << endl;
57
58 try {
59 cout << " ---- Verification operation ------ " << endl;
60 SimpleMatrix<int_4> mx1(4,6);
61 mx1 = 3;
62 mx1 *= 2;
63 cout << " mx1=3; mx1*=2; : " << endl;
64 cout << mx1 << endl;
65 SimpleMatrix<int_4> mx2(4,6);
66 mx2.Init(1,1);
67 SimpleMatrix<int_4> mx3(4,6), mx4;
68 mx3.Init(1000,100);
69 mx4 = mx3+mx2*2 ;
70 cout << " mx2, mx3, mx4=mx3+2mx2 " << endl;
71 cout << mx2 << endl << mx3 << endl << mx4 << endl;
72
73 cout << ">> Test with SimpleMatrix<T>/JET " << endl;
74 PrtTim(" (0) -- ");
75
76 int i,j,k;
77 {
78 SimpleMatrix<r_8> m1(nrow, ncol);
79 SimpleMatrix<r_8> m2(nrow, ncol);
80 SimpleMatrix<r_8> m3(nrow, ncol);
81 SimpleMatrix<r_8> m4(nrow, ncol);
82 SimpleMatrix<r_8> m5(nrow, ncol);
83 for(k=0; k<N; k++) {
84 double xxr = drand01();
85 double yyr = 2.*drand01();
86 for(i=0; i<nrow; i++)
87 for(j=0; j<ncol; j++) {
88 m1(i,j) = k*300+10.*i+j+xxr;
89 m2(i,j) = k*550+20.*i+2.*j+yyr;
90 m3(i,j) = k*860.+40.*i+7.*j+yyr*3.14;
91 }
92 }
93
94 cout << " (1) Element access done ---" << endl;
95 PrtTim(" (1) -- ");
96 // Calcul m1*c1 + m2*c2 + m3*c3;
97 for(k=0; k<N; k++) {
98 double c1 = drand01() + 1.2;
99 double c2 = drand01() + 3.5;
100 double c3 = drand01() + 6.7;
101 m5 = m1; m5.MulCst(c1);
102 m4 = m2; m4.MulCst(c2);
103 m5.AddElt(m4);
104 m4 = m3; m3.MulCst(c2);
105 m5.AddElt(m4);
106 }
107 cout << " (2) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
108 PrtTim(" (2) -- ");
109
110 for(k=0; k<N; k++) {
111 double c1 = drand01() + 1.2;
112 double c2 = drand01() + 3.5;
113 double c3 = drand01() + 6.7;
114 m5 = m1*c1+m2*c2+m3*c3;
115 }
116 cout << " (3) JET: m1*c1 + m2*c2 + m3*c3 done ---" << endl;
117 PrtTim(" (3) -- ");
118 // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
119 for(k=0; k<N; k++) {
120 double c1 = drand01() + 1.2;
121 double c2 = drand01() + 3.5;
122 double c3 = drand01() + 6.7;
123 m3 = m1; m3.MulCst(c1);
124 m4 = m2; m4.AddCst(c2); m4.MulElt(m1);
125 m5 = m2; m5.MulCst(c3);
126 m5.AddElt(m3); m5.AddElt(m4);
127 }
128 cout << " (4) Add/MulElt/Cst m1*c1 + m1*(m2+c2) + m2*c3 done ---" << endl;
129 PrtTim(" (4) --");
130
131 for(k=0; k<N; k++) {
132 double c1 = drand01() + 1.2;
133 double c2 = drand01() + 3.5;
134 double c3 = drand01() + 6.7;
135 // m4 = SMExprAdd< r_8, SMExprMtx<r_8>, SMExprMtx<r_8> >( SMExprMtx<r_8>(m1), SMExprMtx<r_8> (m2) );
136 // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
137 m5 = m1*c1 + m1*(m2+c2) + m2*c3;
138 }
139 cout << " (5) JET: m5 = m1*c1 + m1*(m2+c2) + m2*c3 ---" << endl;
140 PrtTim(" (5) -- ");
141
142 for(k=0; k<N; k++) {
143 double c1 = drand01() + 1.2;
144 double c2 = drand01() + 3.5;
145 double c3 = drand01() + 6.7;
146 // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
147 m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1);
148 }
149 cout << " (6) JET: m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1) ---" << endl;
150 PrtTim(" (6) -- ");
151
152 }
153
154
155 // Test avec les TArray / TMatrix
156 {
157 cout << " >>>>> test with SOPHYA::TArray / TMatrix " << endl;
158 TMatrix<r_8> m1(nrow, ncol);
159 TMatrix<r_8> m2(nrow, ncol);
160 TMatrix<r_8> m3(nrow, ncol);
161 TMatrix<r_8> m4(nrow, ncol);
162 TMatrix<r_8> m5(nrow, ncol);
163 for(k=0; k<N; k++) {
164 double xxr = drand01();
165 double yyr = 2.*drand01();
166 for(i=0; i<nrow; i++)
167 for(j=0; j<ncol; j++) {
168 m1(i,j) = k*300+10.*i+j+xxr;
169 m2(i,j) = k*550+20.*i+2.*j+yyr;
170 m3(i,j) = k*860.+40.*i+7.*j+yyr*3.14;
171 }
172 }
173 cout << " (21) Element access done ---" << endl;
174 PrtTim(" (21) -- ");
175 // Calcul m1*c1 + m2*c2 + m3*c3;
176 for(k=0; k<N; k++) {
177 double c1 = drand01() + 1.2;
178 double c2 = drand01() + 3.5;
179 double c3 = drand01() + 6.7;
180 /* Changement interface SOPHYA : 2004-2005
181 m5 = m1; m5.Mul(c1);
182 m4 = m2; m4.Mul(c2);
183 m5.AddElt(m4);
184 m4 = m3; m3.Mul(c3);
185 m5.AddElt(m4);
186 */
187 m1.MulCst(c1, m5);
188 m2.MulCst(c2, m4);
189 m5.AddElt(m4, m5);
190 m3.MulCst(c3,m4);
191 m4.AddElt(m5,m4);
192 }
193 cout << " (22) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
194 PrtTim(" (22) -- ");
195
196 for(k=0; k<N; k++) {
197 double c1 = drand01() + 1.2;
198 double c2 = drand01() + 3.5;
199 double c3 = drand01() + 6.7;
200 m5 = m1*c1+m2*c2+m3*c3;
201 }
202 cout << " (23) m1*c1 + m2*c2 + m3*c3 done ---" << endl;
203 PrtTim(" (23) -- ");
204
205 for(k=0; k<N; k++) {
206 double c1 = drand01() + 1.2;
207 double c2 = drand01() + 3.5;
208 double c3 = drand01() + 6.7;
209 // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
210 m5 = m1*c1 + m1 && (m2+c2) + m2*c3;
211 }
212 cout << " (25) m5 = m1*c1 + m1*(m2+c2) + m2*c3 ---" << endl;
213 PrtTim(" (25) -- ");
214
215 for(k=0; k<N; k++) {
216 double c1 = drand01() + 1.2;
217 double c2 = drand01() + 3.5;
218 double c3 = drand01() + 6.7;
219 m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1);
220 }
221 cout << " (26) m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1) ---" << endl;
222 PrtTim(" (26) -- ");
223
224 }
225
226 // Test avec des double * x;
227 {
228 cout << " >>>>> test with r_8 * p = new double[size] " << endl;
229 r_8 * m1 = new r_8[nrow*ncol];
230 r_8 * m2 = new r_8[nrow*ncol];
231 r_8 * m3 = new r_8[nrow*ncol];
232 r_8 * m5 = new r_8[nrow*ncol];
233 for(k=0; k<N; k++) {
234 double xxr = drand01();
235 double yyr = 2.*drand01();
236 for(i=0; i<nrow*ncol; i++) {
237 m1[i] = k*300+10.*i+j+xxr;
238 m2[i] = k*550+20.*i+2.*j+yyr;
239 m3[i] = k*860.+40.*i+7.*j+yyr*3.14;
240 }
241 }
242 cout << " (31) p[i] Element access done ---" << endl;
243 PrtTim(" (31) -- ");
244 // Calcul m1*c1 + m2*c2 + m3*c3;
245 for(k=0; k<N; k++) {
246 double c1 = drand01() + 1.2;
247 double c2 = drand01() + 3.5;
248 double c3 = drand01() + 6.7;
249 for(i=0; i<nrow*ncol; i++)
250 m5[i] = c1*m1[i]+c2*m2[i]+c3*m3[i];
251 }
252 cout << " (32) p[i] m1*c1 + m2*c2 + m3*c3 done ---" << endl;
253 PrtTim(" (32) -- ");
254
255 delete[] m1;
256 delete[] m2;
257 delete[] m3;
258 delete[] m5;
259 }
260 }
261 catch (PThrowable exc) {
262 cerr << " te/catched Exception " << exc.Msg() << endl;
263 }
264 catch (...) {
265 cerr << " te/catched unknown (...) exception " << endl;
266 }
267
268 cout << "\n --------------------------------------------------------" << endl;
269 PrtTim("--- End of te ---");
270 cout << " ---- END of te/TemplateExpression programme ------ " << endl;
271 return 0;
272}
273
Note: See TracBrowser for help on using the repository browser.