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