[2362] | 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
|
---|
[4054] | 22 | // revisite : Mars 2012
|
---|
[2362] | 23 | //--------------------------------------------------------
|
---|
| 24 |
|
---|
| 25 | //------- Le code de smtx.cc
|
---|
| 26 |
|
---|
| 27 | #include "smtx.cc"
|
---|
| 28 |
|
---|
| 29 | //-------
|
---|
| 30 | // ------------------------------------------------
|
---|
| 31 | // programme de test template expressions
|
---|
| 32 | // ------------------------------------------------
|
---|
| 33 |
|
---|
| 34 | int 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 |
|
---|
[2365] | 73 | cout << ">> Test with SimpleMatrix<T>/JET " << endl;
|
---|
| 74 | PrtTim(" (0) -- ");
|
---|
| 75 |
|
---|
[2362] | 76 | int i,j,k;
|
---|
[2365] | 77 | {
|
---|
[2362] | 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++) {
|
---|
[4054] | 84 | double xxr = drand01();
|
---|
| 85 | double yyr = 2.*drand01();
|
---|
[2362] | 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 | }
|
---|
[2366] | 93 |
|
---|
[2365] | 94 | cout << " (1) Element access done ---" << endl;
|
---|
| 95 | PrtTim(" (1) -- ");
|
---|
[2362] | 96 | // Calcul m1*c1 + m2*c2 + m3*c3;
|
---|
| 97 | for(k=0; k<N; k++) {
|
---|
[4054] | 98 | double c1 = drand01() + 1.2;
|
---|
| 99 | double c2 = drand01() + 3.5;
|
---|
| 100 | double c3 = drand01() + 6.7;
|
---|
[2362] | 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 | }
|
---|
[2365] | 107 | cout << " (2) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 108 | PrtTim(" (2) -- ");
|
---|
[2362] | 109 |
|
---|
| 110 | for(k=0; k<N; k++) {
|
---|
[4054] | 111 | double c1 = drand01() + 1.2;
|
---|
| 112 | double c2 = drand01() + 3.5;
|
---|
| 113 | double c3 = drand01() + 6.7;
|
---|
[2362] | 114 | m5 = m1*c1+m2*c2+m3*c3;
|
---|
| 115 | }
|
---|
[2365] | 116 | cout << " (3) JET: m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 117 | PrtTim(" (3) -- ");
|
---|
[2362] | 118 | // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
|
---|
| 119 | for(k=0; k<N; k++) {
|
---|
[4054] | 120 | double c1 = drand01() + 1.2;
|
---|
| 121 | double c2 = drand01() + 3.5;
|
---|
| 122 | double c3 = drand01() + 6.7;
|
---|
[2362] | 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 | }
|
---|
[2365] | 128 | cout << " (4) Add/MulElt/Cst m1*c1 + m1*(m2+c2) + m2*c3 done ---" << endl;
|
---|
| 129 | PrtTim(" (4) --");
|
---|
[2362] | 130 |
|
---|
| 131 | for(k=0; k<N; k++) {
|
---|
[4054] | 132 | double c1 = drand01() + 1.2;
|
---|
| 133 | double c2 = drand01() + 3.5;
|
---|
| 134 | double c3 = drand01() + 6.7;
|
---|
[2362] | 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 | }
|
---|
[2365] | 139 | cout << " (5) JET: m5 = m1*c1 + m1*(m2+c2) + m2*c3 ---" << endl;
|
---|
| 140 | PrtTim(" (5) -- ");
|
---|
[2366] | 141 |
|
---|
| 142 | for(k=0; k<N; k++) {
|
---|
[4054] | 143 | double c1 = drand01() + 1.2;
|
---|
| 144 | double c2 = drand01() + 3.5;
|
---|
| 145 | double c3 = drand01() + 6.7;
|
---|
[2366] | 146 | // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
|
---|
| 147 | m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1);
|
---|
[2365] | 148 | }
|
---|
[2366] | 149 | cout << " (6) JET: m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1) ---" << endl;
|
---|
| 150 | PrtTim(" (6) -- ");
|
---|
| 151 |
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 |
|
---|
[2365] | 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++) {
|
---|
[4054] | 164 | double xxr = drand01();
|
---|
| 165 | double yyr = 2.*drand01();
|
---|
[2365] | 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 | }
|
---|
[2366] | 173 | cout << " (21) Element access done ---" << endl;
|
---|
| 174 | PrtTim(" (21) -- ");
|
---|
[2365] | 175 | // Calcul m1*c1 + m2*c2 + m3*c3;
|
---|
| 176 | for(k=0; k<N; k++) {
|
---|
[4054] | 177 | double c1 = drand01() + 1.2;
|
---|
| 178 | double c2 = drand01() + 3.5;
|
---|
| 179 | double c3 = drand01() + 6.7;
|
---|
[2798] | 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);
|
---|
[2365] | 192 | }
|
---|
[2366] | 193 | cout << " (22) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 194 | PrtTim(" (22) -- ");
|
---|
[2365] | 195 |
|
---|
| 196 | for(k=0; k<N; k++) {
|
---|
[4054] | 197 | double c1 = drand01() + 1.2;
|
---|
| 198 | double c2 = drand01() + 3.5;
|
---|
| 199 | double c3 = drand01() + 6.7;
|
---|
[2365] | 200 | m5 = m1*c1+m2*c2+m3*c3;
|
---|
| 201 | }
|
---|
[2366] | 202 | cout << " (23) m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 203 | PrtTim(" (23) -- ");
|
---|
| 204 |
|
---|
| 205 | for(k=0; k<N; k++) {
|
---|
[4054] | 206 | double c1 = drand01() + 1.2;
|
---|
| 207 | double c2 = drand01() + 3.5;
|
---|
| 208 | double c3 = drand01() + 6.7;
|
---|
[2939] | 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++) {
|
---|
[4054] | 216 | double c1 = drand01() + 1.2;
|
---|
| 217 | double c2 = drand01() + 3.5;
|
---|
| 218 | double c3 = drand01() + 6.7;
|
---|
[2366] | 219 | m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1);
|
---|
[2365] | 220 | }
|
---|
[2366] | 221 | cout << " (26) m5 = m1*c1 + m2 + c2*Sin(c3*m3+m1) ---" << endl;
|
---|
| 222 | PrtTim(" (26) -- ");
|
---|
| 223 |
|
---|
| 224 | }
|
---|
[2367] | 225 |
|
---|
| 226 | // Test avec des double * x;
|
---|
| 227 | {
|
---|
[2368] | 228 | cout << " >>>>> test with r_8 * p = new double[size] " << endl;
|
---|
[2367] | 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++) {
|
---|
[4054] | 234 | double xxr = drand01();
|
---|
| 235 | double yyr = 2.*drand01();
|
---|
[2367] | 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++) {
|
---|
[4054] | 246 | double c1 = drand01() + 1.2;
|
---|
| 247 | double c2 = drand01() + 3.5;
|
---|
| 248 | double c3 = drand01() + 6.7;
|
---|
[2367] | 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 | }
|
---|
[2362] | 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 |
|
---|