[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
|
---|
| 22 | //--------------------------------------------------------
|
---|
| 23 |
|
---|
| 24 | //------- Le code de smtx.cc
|
---|
| 25 |
|
---|
| 26 | #include "smtx.cc"
|
---|
| 27 |
|
---|
| 28 | //-------
|
---|
| 29 | // ------------------------------------------------
|
---|
| 30 | // programme de test template expressions
|
---|
| 31 | // ------------------------------------------------
|
---|
| 32 |
|
---|
| 33 | int main(int narg, char* arg[])
|
---|
| 34 | {
|
---|
| 35 |
|
---|
| 36 | SophyaInit();
|
---|
| 37 | InitTim(); // Initializing the CPU timer
|
---|
| 38 |
|
---|
| 39 | if (narg < 3) {
|
---|
| 40 | cout << "\n te/ TemplateExpression Test - missing arguments\n"
|
---|
| 41 | << " Usage: te NLoop NRow NCol \n" << endl;
|
---|
| 42 | return 1;
|
---|
| 43 | }
|
---|
| 44 | int N = 10;
|
---|
| 45 | int nrow = 2;
|
---|
| 46 | int ncol = 2;
|
---|
| 47 |
|
---|
| 48 | N = atoi(arg[1]);
|
---|
| 49 |
|
---|
| 50 | nrow = atoi(arg[2]);
|
---|
| 51 | ncol = atoi(arg[3]);
|
---|
| 52 |
|
---|
| 53 | cout << " te/ TemplateExpression Test - NLoop = " << N
|
---|
| 54 | << " NRow=" << nrow << " NCol= " << ncol
|
---|
| 55 | << " Size=nr*nc= " << nrow*ncol << endl;
|
---|
| 56 |
|
---|
| 57 | try {
|
---|
| 58 | cout << " ---- Verification operation ------ " << endl;
|
---|
| 59 | SimpleMatrix<int_4> mx1(4,6);
|
---|
| 60 | mx1 = 3;
|
---|
| 61 | mx1 *= 2;
|
---|
| 62 | cout << " mx1=3; mx1*=2; : " << endl;
|
---|
| 63 | cout << mx1 << endl;
|
---|
| 64 | SimpleMatrix<int_4> mx2(4,6);
|
---|
| 65 | mx2.Init(1,1);
|
---|
| 66 | SimpleMatrix<int_4> mx3(4,6), mx4;
|
---|
| 67 | mx3.Init(1000,100);
|
---|
| 68 | mx4 = mx3+mx2*2 ;
|
---|
| 69 | cout << " mx2, mx3, mx4=mx3+2mx2 " << endl;
|
---|
| 70 | cout << mx2 << endl << mx3 << endl << mx4 << endl;
|
---|
| 71 |
|
---|
[2365] | 72 | cout << ">> Test with SimpleMatrix<T>/JET " << endl;
|
---|
| 73 | PrtTim(" (0) -- ");
|
---|
| 74 |
|
---|
[2362] | 75 | int i,j,k;
|
---|
[2365] | 76 | {
|
---|
[2362] | 77 | SimpleMatrix<r_8> m1(nrow, ncol);
|
---|
| 78 | SimpleMatrix<r_8> m2(nrow, ncol);
|
---|
| 79 | SimpleMatrix<r_8> m3(nrow, ncol);
|
---|
| 80 | SimpleMatrix<r_8> m4(nrow, ncol);
|
---|
| 81 | SimpleMatrix<r_8> m5(nrow, ncol);
|
---|
| 82 | for(k=0; k<N; k++) {
|
---|
| 83 | double xxr = frand01();
|
---|
| 84 | double yyr = 2.*frand01();
|
---|
| 85 | for(i=0; i<nrow; i++)
|
---|
| 86 | for(j=0; j<ncol; j++) {
|
---|
| 87 | m1(i,j) = k*300+10.*i+j+xxr;
|
---|
| 88 | m2(i,j) = k*550+20.*i+2.*j+yyr;
|
---|
| 89 | m3(i,j) = k*860.+40.*i+7.*j+yyr*3.14;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
[2365] | 92 | cout << " (1) Element access done ---" << endl;
|
---|
| 93 | PrtTim(" (1) -- ");
|
---|
[2362] | 94 | // Calcul m1*c1 + m2*c2 + m3*c3;
|
---|
| 95 | for(k=0; k<N; k++) {
|
---|
| 96 | double c1 = frand01() + 1.2;
|
---|
| 97 | double c2 = frand01() + 3.5;
|
---|
| 98 | double c3 = frand01() + 6.7;
|
---|
| 99 | m5 = m1; m5.MulCst(c1);
|
---|
| 100 | m4 = m2; m4.MulCst(c2);
|
---|
| 101 | m5.AddElt(m4);
|
---|
| 102 | m4 = m3; m3.MulCst(c2);
|
---|
| 103 | m5.AddElt(m4);
|
---|
| 104 | }
|
---|
[2365] | 105 | cout << " (2) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 106 | PrtTim(" (2) -- ");
|
---|
[2362] | 107 |
|
---|
| 108 | for(k=0; k<N; k++) {
|
---|
| 109 | double c1 = frand01() + 1.2;
|
---|
| 110 | double c2 = frand01() + 3.5;
|
---|
| 111 | double c3 = frand01() + 6.7;
|
---|
| 112 | m5 = m1*c1+m2*c2+m3*c3;
|
---|
| 113 | }
|
---|
[2365] | 114 | cout << " (3) JET: m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 115 | PrtTim(" (3) -- ");
|
---|
[2362] | 116 | // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
|
---|
| 117 | for(k=0; k<N; k++) {
|
---|
| 118 | double c1 = frand01() + 1.2;
|
---|
| 119 | double c2 = frand01() + 3.5;
|
---|
| 120 | double c3 = frand01() + 6.7;
|
---|
| 121 | m3 = m1; m3.MulCst(c1);
|
---|
| 122 | m4 = m2; m4.AddCst(c2); m4.MulElt(m1);
|
---|
| 123 | m5 = m2; m5.MulCst(c3);
|
---|
| 124 | m5.AddElt(m3); m5.AddElt(m4);
|
---|
| 125 | }
|
---|
[2365] | 126 | cout << " (4) Add/MulElt/Cst m1*c1 + m1*(m2+c2) + m2*c3 done ---" << endl;
|
---|
| 127 | PrtTim(" (4) --");
|
---|
[2362] | 128 |
|
---|
| 129 | for(k=0; k<N; k++) {
|
---|
| 130 | double c1 = frand01() + 1.2;
|
---|
| 131 | double c2 = frand01() + 3.5;
|
---|
| 132 | double c3 = frand01() + 6.7;
|
---|
| 133 | // m4 = SMExprAdd< r_8, SMExprMtx<r_8>, SMExprMtx<r_8> >( SMExprMtx<r_8>(m1), SMExprMtx<r_8> (m2) );
|
---|
| 134 | // Calcul m1*c1 + m1*(m2+c2) + m2*c3;
|
---|
| 135 | m5 = m1*c1 + m1*(m2+c2) + m2*c3;
|
---|
| 136 | }
|
---|
[2365] | 137 | cout << " (5) JET: m5 = m1*c1 + m1*(m2+c2) + m2*c3 ---" << endl;
|
---|
| 138 | PrtTim(" (5) -- ");
|
---|
| 139 | }
|
---|
| 140 | // Test avec les TArray / TMatrix
|
---|
| 141 | {
|
---|
| 142 | cout << " >>>>> test with SOPHYA::TArray / TMatrix " << endl;
|
---|
| 143 | TMatrix<r_8> m1(nrow, ncol);
|
---|
| 144 | TMatrix<r_8> m2(nrow, ncol);
|
---|
| 145 | TMatrix<r_8> m3(nrow, ncol);
|
---|
| 146 | TMatrix<r_8> m4(nrow, ncol);
|
---|
| 147 | TMatrix<r_8> m5(nrow, ncol);
|
---|
| 148 | for(k=0; k<N; k++) {
|
---|
| 149 | double xxr = frand01();
|
---|
| 150 | double yyr = 2.*frand01();
|
---|
| 151 | for(i=0; i<nrow; i++)
|
---|
| 152 | for(j=0; j<ncol; j++) {
|
---|
| 153 | m1(i,j) = k*300+10.*i+j+xxr;
|
---|
| 154 | m2(i,j) = k*550+20.*i+2.*j+yyr;
|
---|
| 155 | m3(i,j) = k*860.+40.*i+7.*j+yyr*3.14;
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 | cout << " (6) Element access done ---" << endl;
|
---|
| 159 | PrtTim(" (6) -- ");
|
---|
| 160 | // Calcul m1*c1 + m2*c2 + m3*c3;
|
---|
| 161 | for(k=0; k<N; k++) {
|
---|
| 162 | double c1 = frand01() + 1.2;
|
---|
| 163 | double c2 = frand01() + 3.5;
|
---|
| 164 | double c3 = frand01() + 6.7;
|
---|
| 165 | m5 = m1; m5.Mul(c1);
|
---|
| 166 | m4 = m2; m4.Mul(c2);
|
---|
| 167 | m5.AddElt(m4);
|
---|
| 168 | m4 = m3; m3.Mul(c2);
|
---|
| 169 | m5.AddElt(m4);
|
---|
| 170 | }
|
---|
| 171 | cout << " (7) Add/MulElt/Cst m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 172 | PrtTim(" (7) -- ");
|
---|
| 173 |
|
---|
| 174 | for(k=0; k<N; k++) {
|
---|
| 175 | double c1 = frand01() + 1.2;
|
---|
| 176 | double c2 = frand01() + 3.5;
|
---|
| 177 | double c3 = frand01() + 6.7;
|
---|
| 178 | m5 = m1*c1+m2*c2+m3*c3;
|
---|
| 179 | }
|
---|
| 180 | cout << " (8) m1*c1 + m2*c2 + m3*c3 done ---" << endl;
|
---|
| 181 | PrtTim(" (8) -- ");
|
---|
| 182 | }
|
---|
[2362] | 183 | }
|
---|
| 184 | catch (PThrowable exc) {
|
---|
| 185 | cerr << " te/catched Exception " << exc.Msg() << endl;
|
---|
| 186 | }
|
---|
| 187 | catch (...) {
|
---|
| 188 | cerr << " te/catched unknown (...) exception " << endl;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | cout << "\n --------------------------------------------------------" << endl;
|
---|
| 192 | PrtTim("--- End of te ---");
|
---|
| 193 | cout << " ---- END of te/TemplateExpression programme ------ " << endl;
|
---|
| 194 | return 0;
|
---|
| 195 | }
|
---|
| 196 |
|
---|