1 | #include "machdefs.h"
|
---|
2 |
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "tarrinit.h"
|
---|
7 | #include "array.h"
|
---|
8 | #include "timing.h"
|
---|
9 | #include "resusage.h"
|
---|
10 |
|
---|
11 | /* Programme de test de vitesse des operations sur TArray */
|
---|
12 | /* de SOPHYA Reza, Juillet 2004 */
|
---|
13 |
|
---|
14 | /* Flag a activer pour compiler avec SOPHYA V <= 1.7 */
|
---|
15 | /* #define VSOP_17 */
|
---|
16 |
|
---|
17 | int main(int narg, char* arg[])
|
---|
18 | {
|
---|
19 |
|
---|
20 | SophyaInit();
|
---|
21 | InitTim(); // Initializing the CPU timer
|
---|
22 |
|
---|
23 | if (narg < 5) {
|
---|
24 | cout << " spar TSel NLoop NRow NCols \n"
|
---|
25 | << " TSel=0/1/2: Option de selection test 7 avec sous-tableaux \n"
|
---|
26 | << " 0: Ne pas faire test 7 (couteux en V <= 1.7) \n"
|
---|
27 | << " 1: Test 7 1ere partie (sans AA.Row(r)*x+BB.Row(r)*y \n"
|
---|
28 | << " 2: Test 7 complet \n"
|
---|
29 | << " NLoop: Nombre d'iterations \n"
|
---|
30 | << " NRow,NCols: Taille de matrices \n"
|
---|
31 | << " Exemple: spar 0 10 800 1000 (Grande taille memoire) \n"
|
---|
32 | << " spar 1 100 80 100 (Petite taille memoire) \n" << endl;
|
---|
33 | return 1;
|
---|
34 | }
|
---|
35 | int ope = atoi(arg[1]);
|
---|
36 | int nloop = atoi(arg[2]);
|
---|
37 | int nr = atoi(arg[3]);
|
---|
38 | int nc = atoi(arg[4]);
|
---|
39 |
|
---|
40 | cout << " ------------------------------------------------- " << endl;
|
---|
41 | cout << " spar = SpeedArray Ope=" << ope << " NLoop= " << nloop
|
---|
42 | << " NR= " << nr << " NC= " << nc << endl;
|
---|
43 | cout << " ------------------------------------------------- " << endl;
|
---|
44 |
|
---|
45 | ResourceUsage res;
|
---|
46 | cout << "(1) Initialisation matrices Ac,Bc,Af,Bf - Random" << endl;
|
---|
47 | Matrix A(nr, nc, BaseArray::CMemoryMapping);
|
---|
48 | Matrix B(nr, nc, BaseArray::CMemoryMapping);
|
---|
49 | Matrix Ac(nr, nc, BaseArray::CMemoryMapping);
|
---|
50 | Matrix Bc(nr, nc, BaseArray::CMemoryMapping);
|
---|
51 | Matrix Af(nr, nc, BaseArray::FortranMemoryMapping);
|
---|
52 | Matrix Bf(nr, nc, BaseArray::CMemoryMapping);
|
---|
53 |
|
---|
54 | A = RandomSequence(RandomSequence::Flat);
|
---|
55 | B = RandomSequence(RandomSequence::Flat);
|
---|
56 |
|
---|
57 | Ac = A;
|
---|
58 | Bc = B;
|
---|
59 | Af = A;
|
---|
60 | Bf = B;
|
---|
61 |
|
---|
62 | PrtTim("(1) ApresInit Ac,Bc,Af,Bf ");
|
---|
63 | cout << res;
|
---|
64 |
|
---|
65 | long nop, noptot;
|
---|
66 | noptot = 0;
|
---|
67 |
|
---|
68 | cout << "(2) Operations de type A *= c , A += B " << endl;
|
---|
69 | Ac = A; Bc = B;
|
---|
70 | Af = A; Bf = B;
|
---|
71 | for(int k=0; k<nloop; k++) {
|
---|
72 | Ac *= 1.2;
|
---|
73 | Bf *= 1.15;
|
---|
74 | Ac -= Bc;
|
---|
75 | Af += Bf;
|
---|
76 | }
|
---|
77 | nop = nloop*nr*nc*4/1000;
|
---|
78 | cout << "(2) Op A *= c, A += B (KFLOP) = " << nop << endl;
|
---|
79 | noptot += nop;
|
---|
80 | PrtTim(" Apres (2) ");
|
---|
81 |
|
---|
82 | cout << "(3) Operations de type C = A*c , E = A+B " << endl;
|
---|
83 | Ac = A; Bc = B;
|
---|
84 | Af = A; Bf = B;
|
---|
85 | for(int k=0; k<nloop; k++) {
|
---|
86 | Matrix C = Ac*8.5;
|
---|
87 | C = Bf*54.;
|
---|
88 | Matrix E = Ac-Bc;
|
---|
89 | E = Af+Bc;
|
---|
90 | }
|
---|
91 | nop = nloop*nr*nc*4/1000;
|
---|
92 | cout << "(3) Op C = A*c , E = A+B (KFLOP) = " << nop << endl;
|
---|
93 | noptot += nop;
|
---|
94 | PrtTim(" Apres (3) ");
|
---|
95 |
|
---|
96 |
|
---|
97 | cout << "(4) Operations de type C = A*x+B*y " << endl;
|
---|
98 | Ac = A; Bc = B;
|
---|
99 | Af = A; Bf = B;
|
---|
100 | for(int k=0; k<nloop; k++) {
|
---|
101 | Matrix Ccc = Ac*4.+2.5*Bc;
|
---|
102 | Matrix Ccf = Ac*4.+2.5*Bf;
|
---|
103 | Matrix Cff = Af*4.+2.5*Bc;
|
---|
104 | }
|
---|
105 | nop = nloop*3*nr*nc*3/1000;
|
---|
106 | cout << "(4) Op C = A*x+B*y (KFLOP) = " << nop << endl;
|
---|
107 | noptot += nop;
|
---|
108 | PrtTim(" Apres (4) ");
|
---|
109 |
|
---|
110 |
|
---|
111 | cout << "(5) Operations de type C = A*x+B*y-z*A-B*t " << endl;
|
---|
112 | Ac = A; Bc = B;
|
---|
113 | Af = A; Bf = B;
|
---|
114 | for(int k=0; k<nloop; k++) {
|
---|
115 | Matrix Ccc = Ac*4.+2.5*Bc-0.3*Ac-Bc*0.8;
|
---|
116 | Matrix Ccf = Ac*4.+2.5*Bf-0.3*Ac-Bf*0.8;
|
---|
117 | Matrix Cff = Af*4.+2.5*Bf-0.3*Af-Bf*0.8;
|
---|
118 | }
|
---|
119 | nop = nloop*3*nr*nc*7/1000;
|
---|
120 | cout << "(5) Op C = A*x+B*y-z*A-B*t (KFLOP) = " << nop << endl;
|
---|
121 | noptot += nop;
|
---|
122 | PrtTim(" Apres (5) ");
|
---|
123 |
|
---|
124 | cout << "(6) Operations de type (A*x+y*B).MulElt(B-A, ->D) " << endl;
|
---|
125 | Ac = A; Bc = B;
|
---|
126 | Af = A; Bf = B;
|
---|
127 | #ifndef VSOP_17
|
---|
128 | for(int k=0; k<nloop; k++) {
|
---|
129 | Matrix Dc;
|
---|
130 | (Ac+4.+6.5*Bc).MulElt(Bc-Ac, Dc);
|
---|
131 | Matrix Dcf;
|
---|
132 | (Ac+4.+6.5*Bf).MulElt(Bc-Af, Dcf);
|
---|
133 | Matrix Df;
|
---|
134 | (Af+4.+6.5*Bf).MulElt(Bf-Af, Df);
|
---|
135 | }
|
---|
136 | #else
|
---|
137 | for(int k=0; k<nloop; k++) {
|
---|
138 | Matrix Dc;
|
---|
139 | Dc = (Ac+4.+6.5*Bc);
|
---|
140 | Dc.MulElt(Bc-Ac);
|
---|
141 | Matrix Dcf = (Ac+4.+6.5*Bf);
|
---|
142 | Dcf.MulElt(Bc-Af);
|
---|
143 | Matrix Df = (Af+4.+6.5*Bf);
|
---|
144 | Df.MulElt(Bf-Af);
|
---|
145 | }
|
---|
146 | #endif
|
---|
147 | nop = nloop*3*nr*nc*5/1000;
|
---|
148 | cout << "(6) Op (A*x+y*B).MulElt(B-A, ->D) (KFLOP) = " << nop << endl;
|
---|
149 | noptot += nop;
|
---|
150 | PrtTim(" Apres (6) ");
|
---|
151 | cout << res;
|
---|
152 |
|
---|
153 | // Les operations sur sous-tableaux sont beaucoup trop couteux V <= 1.7
|
---|
154 | if (ope > 0) {
|
---|
155 | cout << "\n (7) Operations de AA.Row() *= ... " << endl;
|
---|
156 | Ac = A; Bc = B;
|
---|
157 | Af = A; Bf = B;
|
---|
158 | #ifdef VSOP_17
|
---|
159 | cout << " !!! Operations couteuses en V<=1.7 " << endl;
|
---|
160 | #endif
|
---|
161 | Matrix AA,BB;
|
---|
162 | Vector * vr = new Vector[nr];
|
---|
163 | for(int k=0; k<nloop; k++) {
|
---|
164 | AA = Ac;
|
---|
165 | BB = Bc;
|
---|
166 | for(int r=0; r<nr; r++) {
|
---|
167 | double fac = (5*r+0.33);
|
---|
168 | AA.Row(r) *= fac;
|
---|
169 | BB.Row(r) += AA.Row(r)*4.;
|
---|
170 | if (ope < 2) continue;
|
---|
171 | #ifdef VSOP_17
|
---|
172 | // Attention, si on ne fait pas le SetSize a la main, ca explose en memoire en V <= 1.7
|
---|
173 | vr[r].SetSize(AA.Row(r).Size(), AA.Row(r).GetVectorType());
|
---|
174 | vr[r] = AA.Row(r)*3.14+BB.Row(r)*5.6;
|
---|
175 | #else
|
---|
176 | vr[r] = AA.Row(r)*3.14+BB.Row(r)*5.6;
|
---|
177 | #endif
|
---|
178 | }
|
---|
179 | }
|
---|
180 | if (ope < 2) nop = nloop*nr*nc*3/1000;
|
---|
181 | else nop = nloop*nr*nc*6/1000;
|
---|
182 | cout << "(7) Op AA.Row() *= (KFLOP) = " << nop << endl;
|
---|
183 | noptot += nop;
|
---|
184 | PrtTim(" Apres (7) ");
|
---|
185 | cout << res;
|
---|
186 | delete[] vr;
|
---|
187 | }
|
---|
188 | cout << " ------------------------------------------------- " << endl;
|
---|
189 | cout << res;
|
---|
190 | PrtTim("Fin spar ");
|
---|
191 | cout << " ------ Fin spar N_OP_TOT= " << noptot << " (KFLOP) ------- " << endl;
|
---|
192 | }
|
---|