| [991] | 1 | #include <stdlib.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 |
|
|---|
| 4 | #include <exception>
|
|---|
| 5 | #include <string>
|
|---|
| 6 |
|
|---|
| 7 | #ifdef USEVECSTL
|
|---|
| 8 | #include <vector>
|
|---|
| 9 | #endif
|
|---|
| 10 |
|
|---|
| 11 | class MyException : public exception
|
|---|
| 12 | {
|
|---|
| 13 | public:
|
|---|
| 14 | MyException(const char * msg) { _msg = msg; }
|
|---|
| 15 | // ~MyException() { }
|
|---|
| 16 | string Msg() { return(_msg); }
|
|---|
| 17 | private:
|
|---|
| 18 | string _msg;
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | template<class T> class Vector
|
|---|
| 22 | {
|
|---|
| 23 | private:
|
|---|
| 24 | #ifdef USEVECSTL
|
|---|
| 25 | vector<T> data;
|
|---|
| 26 | #else
|
|---|
| 27 | T* data;
|
|---|
| 28 | #endif
|
|---|
| 29 | int size;
|
|---|
| 30 |
|
|---|
| 31 | public:
|
|---|
| 32 | Vector (int s, bool fg=false);
|
|---|
| 33 | ~Vector ();
|
|---|
| 34 |
|
|---|
| 35 | inline T elem (int pos) const { return data[pos]; }
|
|---|
| 36 | inline T& elem (int pos) { return data[pos]; }
|
|---|
| 37 |
|
|---|
| 38 | inline T elemCk (int pos) const
|
|---|
| 39 | { if ((pos < 0) || (pos >= size)) throw MyException("Vector<T> Out of bound");
|
|---|
| 40 | return data[pos]; }
|
|---|
| 41 |
|
|---|
| 42 | inline T& elemCk (int pos)
|
|---|
| 43 | { if ((pos < 0) || (pos >= size)) throw MyException("Vector<T> Out of bound");
|
|---|
| 44 | return data[pos]; }
|
|---|
| 45 |
|
|---|
| 46 | inline int getSize () const { return size; }
|
|---|
| 47 |
|
|---|
| 48 | // Addition et multiplication en utilisant elem()
|
|---|
| 49 | Vector<T> * Add(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 50 | Vector<T> * Mult(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 51 | // Addition et multiplication en utilisant elemCk()
|
|---|
| 52 | Vector<T> * AddCk(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 53 | Vector<T> * MultCk(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 54 | // Addition et multiplication en utilisant des pointeurs
|
|---|
| 55 | Vector<T> * AddP(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 56 | Vector<T> * MultP(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 57 | // Addition et multiplication en utilisant des pointeurs et p[i]
|
|---|
| 58 | Vector<T> * AddPE(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 59 | Vector<T> * MultPE(Vector<T> & v1, Vector<T> & v2);
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | template<class T> Vector<T>::Vector (int s, bool fg)
|
|---|
| 63 | {
|
|---|
| 64 | int k;
|
|---|
| 65 | if (s < 1) s = 1;
|
|---|
| 66 | size = s;
|
|---|
| 67 | #ifdef USEVECSTL
|
|---|
| 68 | for(k=0; k<s; k++) data.push_back((T)0);
|
|---|
| 69 | #else
|
|---|
| 70 | data = new T[size];
|
|---|
| 71 | if (!fg) return;
|
|---|
| 72 |
|
|---|
| 73 | T * p = data;
|
|---|
| 74 | for(k=0; k<s; k++) *p++ = (T)0;
|
|---|
| 75 | #endif
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | template<class T> Vector<T>::~Vector()
|
|---|
| 79 | {
|
|---|
| 80 | size = 0;
|
|---|
| 81 | #ifdef USEVECSTL
|
|---|
| 82 | #else
|
|---|
| 83 | delete[] data;
|
|---|
| 84 | #endif
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | template<class T> Vector<T> * Vector<T>::Add(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 90 | {
|
|---|
| 91 | int i;
|
|---|
| 92 |
|
|---|
| 93 | for (i = 0; i < size; i++)
|
|---|
| 94 | elem(i) = v1.elem(i)+v2.elem(i);
|
|---|
| 95 | return (this);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | template<class T> Vector<T> * Vector<T>::Mult(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 99 | {
|
|---|
| 100 | int i;
|
|---|
| 101 |
|
|---|
| 102 | for (i = 0; i < size; i++)
|
|---|
| 103 | elem(i) = v1.elem(i)*v2.elem(i);
|
|---|
| 104 | return (this);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | template<class T> Vector<T> * Vector<T>::AddCk(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 109 | {
|
|---|
| 110 | int i;
|
|---|
| 111 |
|
|---|
| 112 | for (i = 0; i < size; i++)
|
|---|
| 113 | elemCk(i) = v1.elemCk(i)+v2.elemCk(i);
|
|---|
| 114 | return (this);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | template<class T> Vector<T> * Vector<T>::MultCk(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 118 | {
|
|---|
| 119 | int i;
|
|---|
| 120 |
|
|---|
| 121 | for (i = 0; i < size; i++)
|
|---|
| 122 | elemCk(i) = v1.elemCk(i)*v2.elemCk(i);
|
|---|
| 123 | return (this);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | template<class T> Vector<T> * Vector<T>::AddP(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 127 | {
|
|---|
| 128 | int i;
|
|---|
| 129 | #ifdef USEVECSTL
|
|---|
| 130 | vector<T>::iterator p = data.begin();
|
|---|
| 131 | vector<T>::iterator p1 = v1.data.begin();
|
|---|
| 132 | vector<T>::iterator p2 = v2.data.begin();
|
|---|
| 133 | #else
|
|---|
| 134 | T * p = data;
|
|---|
| 135 | T * p1 = v1.data;
|
|---|
| 136 | T * p2 = v2.data;
|
|---|
| 137 | #endif
|
|---|
| 138 | for (i = 0; i < size; i++) *p++ = *p1++ + *p2++;
|
|---|
| 139 | return (this);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | template<class T> Vector<T> * Vector<T>::MultP(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 143 | {
|
|---|
| 144 | int i;
|
|---|
| 145 | #ifdef USEVECSTL
|
|---|
| 146 | vector<T>::iterator p = data.begin();
|
|---|
| 147 | vector<T>::iterator p1 = v1.data.begin();
|
|---|
| 148 | vector<T>::iterator p2 = v2.data.begin();
|
|---|
| 149 | #else
|
|---|
| 150 | T * p = data;
|
|---|
| 151 | T * p1 = v1.data;
|
|---|
| 152 | T * p2 = v2.data;
|
|---|
| 153 | #endif
|
|---|
| 154 | for (i = 0; i < size; i++) *p++ = *p1++ * *p2++;
|
|---|
| 155 | return (this);
|
|---|
| 156 | }
|
|---|
| 157 | template<class T> Vector<T> * Vector<T>::AddPE(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 158 | {
|
|---|
| 159 | int i;
|
|---|
| 160 | #ifdef USEVECSTL
|
|---|
| 161 | vector<T>::iterator p = data.begin();
|
|---|
| 162 | vector<T>::iterator p1 = v1.data.begin();
|
|---|
| 163 | vector<T>::iterator p2 = v2.data.begin();
|
|---|
| 164 | #else
|
|---|
| 165 | T * p = data;
|
|---|
| 166 | T * p1 = v1.data;
|
|---|
| 167 | T * p2 = v2.data;
|
|---|
| 168 | #endif
|
|---|
| 169 | for (i = 0; i < size; i++) p[i] = p1[i] + p2[i];
|
|---|
| 170 | return (this);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | template<class T> Vector<T> * Vector<T>::MultPE(Vector<T> &v1, Vector<T> &v2)
|
|---|
| 174 | {
|
|---|
| 175 | int i;
|
|---|
| 176 | #ifdef USEVECSTL
|
|---|
| 177 | vector<T>::iterator p = data.begin();
|
|---|
| 178 | vector<T>::iterator p1 = v1.data.begin();
|
|---|
| 179 | vector<T>::iterator p2 = v2.data.begin();
|
|---|
| 180 | #else
|
|---|
| 181 | T * p = data;
|
|---|
| 182 | T * p1 = v1.data;
|
|---|
| 183 | T * p2 = v2.data;
|
|---|
| 184 | #endif
|
|---|
| 185 | for (i = 0; i < size; i++) p[i] = p1[i] * p2[i];
|
|---|
| 186 | return (this);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | extern "C" void InitTim();
|
|---|
| 191 | extern "C" void PrtTim(char *Comm);
|
|---|
| 192 |
|
|---|
| 193 | /* --------------------------------------------------------------------- */
|
|---|
| 194 | /* --------------------------- Main Program ---------------------------- */
|
|---|
| 195 | /* --------------------------------------------------------------------- */
|
|---|
| 196 |
|
|---|
| 197 | int main (int narg, char *arg[])
|
|---|
| 198 | {
|
|---|
| 199 |
|
|---|
| 200 | int pos, N, M, OPT, OPE, i;
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | if (narg < 2) {
|
|---|
| 204 | printf("\n Usage: vectorC++ Type(=1,2,3 Int,Float,Double) Ope(=1/2/3/4/5/6/7/8) [N [M] ] \n");
|
|---|
| 205 | printf("Ope: 1=Create/Delete 2=1+FillVect \n");
|
|---|
| 206 | printf("Ope: 3=AddP 4=Mult P (Using pointers) \n");
|
|---|
| 207 | printf("Ope: 5=AddPE 6=MultPE (Using pointers p[]) \n");
|
|---|
| 208 | printf("Ope: 7=Add 8=Mul t (Using elem()) \n");
|
|---|
| 209 | printf("Ope: 9=AddCk 10=MultCk (Using elemCk() - with bound checking) \n");
|
|---|
| 210 | printf("N: Number of operations (def= 100) \n");
|
|---|
| 211 | printf("M: Vector size (def= 50000) \n\n");
|
|---|
| 212 | exit(0);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | InitTim();
|
|---|
| 216 |
|
|---|
| 217 | OPT = 1; OPE = 1;
|
|---|
| 218 | if (narg > 1) OPT = atoi(arg[1]);
|
|---|
| 219 | if ( (OPT < 1) || (OPT > 3) ) OPT = 1;
|
|---|
| 220 |
|
|---|
| 221 | if (narg > 2) OPE = atoi(arg[2]);
|
|---|
| 222 | if ( (OPE < 1) || (OPE > 10) ) OPE = 1;
|
|---|
| 223 |
|
|---|
| 224 | N = 100;
|
|---|
| 225 | if (narg > 3) N = atoi(arg[3]);
|
|---|
| 226 | if (N < 1) N = 1;
|
|---|
| 227 | if (N > 100000) N = 100000;
|
|---|
| 228 | M = 50000;
|
|---|
| 229 | if (narg > 4) M = atoi(arg[4]);
|
|---|
| 230 | if (M < 1000) M = 1000;
|
|---|
| 231 | if (M > 1000000) M = 1000000;
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 | printf(" VectorC++ TestSpeed Typ=%d Ope=%d N=%d VSz=%d\n", OPT, OPE, N,M);
|
|---|
| 235 | #ifdef USEVECSTL
|
|---|
| 236 | printf(" ---------- Using STL vector<T> inside Vector<T> ------------ \n");
|
|---|
| 237 | #endif
|
|---|
| 238 |
|
|---|
| 239 | if (OPE < 3) { /* Test creation / destruction */
|
|---|
| 240 | int fg = OPE-1;
|
|---|
| 241 | bool fgf = (fg != 0) ? true : false;
|
|---|
| 242 | printf("\n\n Test new/delete Vector<T> - fg= %d ( <> 0 ---> FillVec) \n", fg);
|
|---|
| 243 | switch (OPT)
|
|---|
| 244 | {
|
|---|
| 245 | case 1 :
|
|---|
| 246 | {
|
|---|
| 247 | Vector<int> * v;
|
|---|
| 248 | printf("Test %d new/delete Vector<int>[%d] \n",N,M);
|
|---|
| 249 | for(i=0; i<N; i++) {
|
|---|
| 250 | v = new Vector<int>(M, fgf);
|
|---|
| 251 | delete v;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | break;
|
|---|
| 255 | case 2 :
|
|---|
| 256 | {
|
|---|
| 257 | Vector<float> * v;
|
|---|
| 258 | printf("Test %d new/delete Vector<float>[%d] \n",N,M);
|
|---|
| 259 | for(i=0; i<N; i++) {
|
|---|
| 260 | v = new Vector<float>(M, fgf);
|
|---|
| 261 | delete v;
|
|---|
| 262 | }
|
|---|
| 263 | }
|
|---|
| 264 | break;
|
|---|
| 265 | case 3 :
|
|---|
| 266 | {
|
|---|
| 267 | Vector<double> * v;
|
|---|
| 268 | printf("Test %d new/delete Vector<double>[%d] \n",N,M);
|
|---|
| 269 | for(i=0; i<N; i++) {
|
|---|
| 270 | v = new Vector<double>(M, fgf);
|
|---|
| 271 | delete v;
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 | break;
|
|---|
| 275 | }
|
|---|
| 276 | PrtTim("Fin New/Delete ");
|
|---|
| 277 | printf(" .......... Fin de VectorC++ ........... \n");
|
|---|
| 278 | return (0);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | // ---------- Test Addition, Multiplication -------------
|
|---|
| 282 |
|
|---|
| 283 | switch (OPT)
|
|---|
| 284 | {
|
|---|
| 285 | case 1 :
|
|---|
| 286 | {
|
|---|
| 287 | printf("\n\n Test %d operations Vector<int>[%d] \n",N,M);
|
|---|
| 288 |
|
|---|
| 289 | Vector<int> *v1,*v2,*v3;
|
|---|
| 290 | v1 = new Vector<int>(M);
|
|---|
| 291 | v2 = new Vector<int>(M);
|
|---|
| 292 | v3 = new Vector<int>(M);
|
|---|
| 293 | PrtTim("Fin_Creation ");
|
|---|
| 294 |
|
|---|
| 295 | for(pos=0; pos<M; pos++)
|
|---|
| 296 | { v1->elem(pos) = random()%1000;
|
|---|
| 297 | v2->elem(pos) = random()%5000; }
|
|---|
| 298 |
|
|---|
| 299 | PrtTim("Fin remplissage ");
|
|---|
| 300 |
|
|---|
| 301 | if (OPE == 3) {
|
|---|
| 302 | for(pos=0; pos<N; pos++)
|
|---|
| 303 | v3->AddP(*v1, *v2);
|
|---|
| 304 | PrtTim("Fin Addition AddP");
|
|---|
| 305 | }
|
|---|
| 306 | else if (OPE == 4) {
|
|---|
| 307 | for(pos=0; pos<N; pos++)
|
|---|
| 308 | v3->MultP(*v1, *v2);
|
|---|
| 309 | PrtTim("Fin Multiplication MultP");
|
|---|
| 310 | }
|
|---|
| 311 | else if (OPE == 5) {
|
|---|
| 312 | for(pos=0; pos<N; pos++)
|
|---|
| 313 | v3->AddPE(*v1, *v2);
|
|---|
| 314 | PrtTim("Fin Addition AddPE p[i]");
|
|---|
| 315 | }
|
|---|
| 316 | else if (OPE == 6) {
|
|---|
| 317 | for(pos=0; pos<N; pos++)
|
|---|
| 318 | v3->MultPE(*v1, *v2);
|
|---|
| 319 | PrtTim("Fin Multiplication MultPE p[i]");
|
|---|
| 320 | }
|
|---|
| 321 | else if (OPE == 7) {
|
|---|
| 322 | for(pos=0; pos<N; pos++)
|
|---|
| 323 | v3->Add(*v1, *v2);
|
|---|
| 324 | PrtTim("Fin Addition Add");
|
|---|
| 325 | }
|
|---|
| 326 | else if (OPE == 8) {
|
|---|
| 327 | for(pos=0; pos<N; pos++)
|
|---|
| 328 | v3->Mult(*v1, *v2);
|
|---|
| 329 | PrtTim("Fin Multiplication Mult");
|
|---|
| 330 | }
|
|---|
| 331 | else if (OPE == 9) {
|
|---|
| 332 | for(pos=0; pos<N; pos++)
|
|---|
| 333 | v3->AddCk(*v1, *v2);
|
|---|
| 334 | PrtTim("Fin Addition AddCk");
|
|---|
| 335 | }
|
|---|
| 336 | else if (OPE == 10) {
|
|---|
| 337 | for(pos=0; pos<N; pos++)
|
|---|
| 338 | v3->MultCk(*v1, *v2);
|
|---|
| 339 | PrtTim("Fin Multiplication MultCk");
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | printf("Result[1.2] I1= %d %d I2= %d %d I3= %d %d \n",
|
|---|
| 343 | v1->elem(1),v1->elem(2), v2->elem(1),v2->elem(2),
|
|---|
| 344 | v3->elem(1),v3->elem(2));
|
|---|
| 345 | printf("ResAdd[991-2] I1= %d %d I2= %d %d I3= %d %d \n",
|
|---|
| 346 | v1->elem(991),v1->elem(992), v2->elem(991),v2->elem(992),
|
|---|
| 347 | v3->elem(991),v3->elem(992));
|
|---|
| 348 | }
|
|---|
| 349 | break;
|
|---|
| 350 |
|
|---|
| 351 | case 2 :
|
|---|
| 352 | {
|
|---|
| 353 | printf("\n\n Test %d operations Vector<float>[%d] \n",N,M);
|
|---|
| 354 | Vector<float> *v1,*v2,*v3;
|
|---|
| 355 | v1 = new Vector<float>(M);
|
|---|
| 356 | v2 = new Vector<float>(M);
|
|---|
| 357 | v3 = new Vector<float>(M);
|
|---|
| 358 | PrtTim("Fin_Creation ");
|
|---|
| 359 |
|
|---|
| 360 | for(pos=0; pos<M; pos++)
|
|---|
| 361 | { v1->elem(pos) = (float)(random()%1000)/250.;
|
|---|
| 362 | v2->elem(pos) = (float)(random()%5000)/250.; }
|
|---|
| 363 |
|
|---|
| 364 | PrtTim("Fin remplissage ");
|
|---|
| 365 | if (OPE == 3) {
|
|---|
| 366 | for(pos=0; pos<N; pos++)
|
|---|
| 367 | v3->AddP(*v1, *v2);
|
|---|
| 368 | PrtTim("Fin Addition AddP");
|
|---|
| 369 | }
|
|---|
| 370 | else if (OPE == 4) {
|
|---|
| 371 | for(pos=0; pos<N; pos++)
|
|---|
| 372 | v3->MultP(*v1, *v2);
|
|---|
| 373 | PrtTim("Fin Multiplication MultP");
|
|---|
| 374 | }
|
|---|
| 375 | if (OPE == 5) {
|
|---|
| 376 | for(pos=0; pos<N; pos++)
|
|---|
| 377 | v3->AddPE(*v1, *v2);
|
|---|
| 378 | PrtTim("Fin Addition AddPE p[i]");
|
|---|
| 379 | }
|
|---|
| 380 | else if (OPE == 6) {
|
|---|
| 381 | for(pos=0; pos<N; pos++)
|
|---|
| 382 | v3->MultPE(*v1, *v2);
|
|---|
| 383 | PrtTim("Fin Multiplication MultPe p[i]");
|
|---|
| 384 | }
|
|---|
| 385 | else if (OPE == 7) {
|
|---|
| 386 | for(pos=0; pos<N; pos++)
|
|---|
| 387 | v3->Add(*v1, *v2);
|
|---|
| 388 | PrtTim("Fin Addition Add");
|
|---|
| 389 | }
|
|---|
| 390 | else if (OPE == 8) {
|
|---|
| 391 | for(pos=0; pos<N; pos++)
|
|---|
| 392 | v3->Mult(*v1, *v2);
|
|---|
| 393 | PrtTim("Fin Multiplication Mult");
|
|---|
| 394 | }
|
|---|
| 395 | else if (OPE == 9) {
|
|---|
| 396 | for(pos=0; pos<N; pos++)
|
|---|
| 397 | v3->AddCk(*v1, *v2);
|
|---|
| 398 | PrtTim("Fin Addition AddCk");
|
|---|
| 399 | }
|
|---|
| 400 | else if (OPE == 10) {
|
|---|
| 401 | for(pos=0; pos<N; pos++)
|
|---|
| 402 | v3->MultCk(*v1, *v2);
|
|---|
| 403 | PrtTim("Fin Multiplication MultCk");
|
|---|
| 404 | }
|
|---|
| 405 | printf("Result[1.2] F1= %g %g F2= %g %g F3= %g %g \n",
|
|---|
| 406 | v1->elem(1),v1->elem(2), v2->elem(1),v2->elem(2),
|
|---|
| 407 | v3->elem(1),v3->elem(2));
|
|---|
| 408 | printf("Result[991-2] F1= %g %g F2= %g %g F3= %g %g \n",
|
|---|
| 409 | v1->elem(991),v1->elem(992), v2->elem(991),v2->elem(992),
|
|---|
| 410 | v3->elem(991),v3->elem(992));
|
|---|
| 411 | }
|
|---|
| 412 | break;
|
|---|
| 413 |
|
|---|
| 414 | case 3 :
|
|---|
| 415 | {
|
|---|
| 416 | printf("\n\n Test %d operations Vector<double>[%d] \n",N,M);
|
|---|
| 417 | Vector<double> *v1,*v2,*v3;
|
|---|
| 418 | v1 = new Vector<double>(M);
|
|---|
| 419 | v2 = new Vector<double>(M);
|
|---|
| 420 | v3 = new Vector<double>(M);
|
|---|
| 421 | PrtTim("Fin_Creation ");
|
|---|
| 422 |
|
|---|
| 423 | for(pos=0; pos<M; pos++)
|
|---|
| 424 | { v1->elem(pos) = (double)(random()%1000)/250.;
|
|---|
| 425 | v2->elem(pos) = (double)(random()%5000)/250.; }
|
|---|
| 426 |
|
|---|
| 427 | PrtTim("Fin remplissage ");
|
|---|
| 428 | if (OPE == 3) {
|
|---|
| 429 | for(pos=0; pos<N; pos++)
|
|---|
| 430 | v3->AddP(*v1, *v2);
|
|---|
| 431 | PrtTim("Fin Addition AddP");
|
|---|
| 432 | }
|
|---|
| 433 | else if (OPE == 4) {
|
|---|
| 434 | for(pos=0; pos<N; pos++)
|
|---|
| 435 | v3->MultP(*v1, *v2);
|
|---|
| 436 | PrtTim("Fin Multiplication MultP");
|
|---|
| 437 | }
|
|---|
| 438 | else if (OPE == 5) {
|
|---|
| 439 | for(pos=0; pos<N; pos++)
|
|---|
| 440 | v3->AddPE(*v1, *v2);
|
|---|
| 441 | PrtTim("Fin Addition AddPE p[i]");
|
|---|
| 442 | }
|
|---|
| 443 | else if (OPE == 6) {
|
|---|
| 444 | for(pos=0; pos<N; pos++)
|
|---|
| 445 | v3->MultPE(*v1, *v2);
|
|---|
| 446 | PrtTim("Fin Multiplication MultPE p[i]");
|
|---|
| 447 | }
|
|---|
| 448 | else if (OPE == 7) {
|
|---|
| 449 | for(pos=0; pos<N; pos++)
|
|---|
| 450 | v3->Add(*v1, *v2);
|
|---|
| 451 | PrtTim("Fin Addition Add");
|
|---|
| 452 | }
|
|---|
| 453 | else if (OPE == 8) {
|
|---|
| 454 | for(pos=0; pos<N; pos++)
|
|---|
| 455 | v3->Mult(*v1, *v2);
|
|---|
| 456 | PrtTim("Fin Multiplication Mult");
|
|---|
| 457 | }
|
|---|
| 458 | else if (OPE == 9) {
|
|---|
| 459 | for(pos=0; pos<N; pos++)
|
|---|
| 460 | v3->AddCk(*v1, *v2);
|
|---|
| 461 | PrtTim("Fin Addition AddCk");
|
|---|
| 462 | }
|
|---|
| 463 | else if (OPE == 10) {
|
|---|
| 464 | for(pos=0; pos<N; pos++)
|
|---|
| 465 | v3->MultCk(*v1, *v2);
|
|---|
| 466 | PrtTim("Fin Multiplication MultCk");
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | printf("Result[1.2] D1= %g %g D2= %g %g D3= %g %g \n",
|
|---|
| 470 | v1->elem(1),v1->elem(2), v2->elem(1),v2->elem(2),
|
|---|
| 471 | v3->elem(1),v3->elem(2));
|
|---|
| 472 | printf("Result[991-2] D1= %g %g D2= %g %g D3= %g %g \n",
|
|---|
| 473 | v1->elem(991),v1->elem(992), v2->elem(991),v2->elem(992),
|
|---|
| 474 | v3->elem(991),v3->elem(992));
|
|---|
| 475 | }
|
|---|
| 476 | break;
|
|---|
| 477 |
|
|---|
| 478 | default:
|
|---|
| 479 | puts("Erreur d'option !");
|
|---|
| 480 | break;
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 | PrtTim("Fin de Vector/C++ ");
|
|---|
| 486 | printf(" .......... Fin de VectorC++ ........... \n");
|
|---|
| 487 | return (0);
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | /*
|
|---|
| 491 | #ifdef DECCXX
|
|---|
| 492 | #pragma define_template Vector<int>
|
|---|
| 493 | #pragma define_template Vector<float>
|
|---|
| 494 | #pragma define_template Vector<double>
|
|---|
| 495 | #endif
|
|---|
| 496 |
|
|---|
| 497 | #if defined(GNUGCC) || defined (HPaCC)
|
|---|
| 498 | template class Vector<int>;
|
|---|
| 499 | template class Vector<float>;
|
|---|
| 500 | template class Vector<double>;
|
|---|
| 501 | #endif
|
|---|
| 502 |
|
|---|
| 503 | */
|
|---|