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