| 1 | #include<iostream>
 | 
|---|
| 2 | #include"CLHEP/Matrix/Matrix.h"
 | 
|---|
| 3 | #include"CLHEP/Matrix/SymMatrix.h"
 | 
|---|
| 4 | 
 | 
|---|
| 5 | /* -------------------------------------------------
 | 
|---|
| 6 |     Test comparatif (pour SOPHYA) des matrices CLHep
 | 
|---|
| 7 |                             R. Ansari , Juin 2005
 | 
|---|
| 8 | 
 | 
|---|
| 9 |     Pour compiler :
 | 
|---|
| 10 |     definir flag/chemin include et librariries CLHep,
 | 
|---|
| 11 |     Au CC-IN2P3 par exemple, 
 | 
|---|
| 12 |     csh> set inchep = '-I/usr/local/lhcxx/CLHEP/pro/include/'
 | 
|---|
| 13 |     csh> set libhep = '-L/usr/local/lhcxx/CLHEP/pro/lib -lCLHEP'
 | 
|---|
| 14 |     csh> cc -c timing.c 
 | 
|---|
| 15 |     csh> g++ -c $inchep mtxclhep.cc
 | 
|---|
| 16 |     csh> g++ -o mtxclhep mtxclhep.o timing.o $libhep
 | 
|---|
| 17 | 
 | 
|---|
| 18 |     Execution :
 | 
|---|
| 19 |     Acces aux elements et operation add/multcst
 | 
|---|
| 20 |     csh> time ./mtxclhep 50 1000 500
 | 
|---|
| 21 |     Inversion / multiplication
 | 
|---|
| 22 |     csh> time ./mtxclhep 1 1000 1000
 | 
|---|
| 23 |     ------------------------------------------- */
 | 
|---|
| 24 | 
 | 
|---|
| 25 | 
 | 
|---|
| 26 | extern "C" {
 | 
|---|
| 27 | void InitTim(void);
 | 
|---|
| 28 | void PrtTim(const char *Comm);
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | using namespace std;
 | 
|---|
| 32 | 
 | 
|---|
| 33 | int main(int narg, char* arg[])
 | 
|---|
| 34 | {
 | 
|---|
| 35 |   
 | 
|---|
| 36 |   if (narg < 3) {
 | 
|---|
| 37 |     cout << "\n mtxclhep - missing arguments\n" 
 | 
|---|
| 38 |          << "     Usage:  mtxclhep NLoop NRow NCol \n"  
 | 
|---|
| 39 |          << " if nrow==ncol ==>  test inverse/mtx multiply (one time)" << endl;
 | 
|---|
| 40 |     return 1;
 | 
|---|
| 41 |   }
 | 
|---|
| 42 | 
 | 
|---|
| 43 |   int N = 10;
 | 
|---|
| 44 |   int nrow = 2; 
 | 
|---|
| 45 |   int ncol = 2;
 | 
|---|
| 46 | 
 | 
|---|
| 47 |   N = atoi(arg[1]);
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   nrow = atoi(arg[2]);
 | 
|---|
| 50 |   ncol = atoi(arg[3]);
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   cout << " ---- mtxclhep: NLoop=" << N << " NRow= " << nrow 
 | 
|---|
| 53 |        << " NCol= " << ncol << " ---- " << endl;
 | 
|---|
| 54 |   
 | 
|---|
| 55 |   InitTim();
 | 
|---|
| 56 |   srand48(10);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   //ATTENTION :  L'indexage commence a 1 
 | 
|---|
| 59 |   try {
 | 
|---|
| 60 |     int i,j,k;
 | 
|---|
| 61 | 
 | 
|---|
| 62 |     HepMatrix m1(nrow, ncol);
 | 
|---|
| 63 |     HepMatrix m2(nrow, ncol);
 | 
|---|
| 64 |     HepMatrix m3(nrow, ncol);
 | 
|---|
| 65 |     HepMatrix m4(nrow, ncol);
 | 
|---|
| 66 |     HepMatrix m5(nrow, ncol);
 | 
|---|
| 67 | 
 | 
|---|
| 68 |  
 | 
|---|
| 69 |     for(k=0; k<N; k++) {
 | 
|---|
| 70 |       double xxr = drand48();
 | 
|---|
| 71 |       double yyr = 2.*drand48();
 | 
|---|
| 72 |       for(i=1; i<=nrow; i++)
 | 
|---|
| 73 |         for(j=1; j<=ncol; j++) {
 | 
|---|
| 74 |           m1(i,j) = k*300+10.*i+j+xxr;  
 | 
|---|
| 75 |           m2(i,j) = k*550+20.*i+2.*j+yyr;
 | 
|---|
| 76 |           m3(i,j) = k*860.+40.*i+7.*j+yyr*3.14;
 | 
|---|
| 77 |         }
 | 
|---|
| 78 |     }
 | 
|---|
| 79 |     cout << " (1) Element access done ---" << endl;
 | 
|---|
| 80 |     PrtTim(" (1) -- ");
 | 
|---|
| 81 |  
 | 
|---|
| 82 |     for(k=0; k<N; k++) {
 | 
|---|
| 83 |       double c1 = drand48() + 1.2;
 | 
|---|
| 84 |       double c2 = drand48() + 3.5;
 | 
|---|
| 85 |       double c3 = drand48() + 6.7;
 | 
|---|
| 86 |       m5 = m1*c1+m2*c2+m3*c3;
 | 
|---|
| 87 |     }
 | 
|---|
| 88 |     cout << " (3) Add/CstMult: m1*c1 + m2*c2 + m3*c3 done ---" << endl;
 | 
|---|
| 89 |     PrtTim(" (3) -- ");
 | 
|---|
| 90 | 
 | 
|---|
| 91 |   
 | 
|---|
| 92 |   
 | 
|---|
| 93 |     if (nrow == ncol) {
 | 
|---|
| 94 |       cout << " mtxclhep/inverse , mtx multiply A(N,N)  N=" << nrow << endl;
 | 
|---|
| 95 |       HepMatrix A(nrow, nrow);
 | 
|---|
| 96 |       
 | 
|---|
| 97 |       for(i=1; i<=nrow; i++)
 | 
|---|
| 98 |         for(j=0; j<=nrow; j++)   A(i,j) = drand48();
 | 
|---|
| 99 |       
 | 
|---|
| 100 |       cout << " (91)  A(i,j) = drand48() done ---" << endl;
 | 
|---|
| 101 |       PrtTim(" (91) -- ");
 | 
|---|
| 102 |       
 | 
|---|
| 103 |       int ierr;
 | 
|---|
| 104 |       HepMatrix Ainv = A.inverse(ierr);
 | 
|---|
| 105 |       cout << " (92)  Ainv = A.inverse() done ---" << endl;
 | 
|---|
| 106 |       PrtTim(" (92) -- ");
 | 
|---|
| 107 |       if (ierr == 0) {
 | 
|---|
| 108 |         cout << " A.inverse(ierr) OK computing A*Ainv ..." << endl; 
 | 
|---|
| 109 |         HepMatrix mxx = A*Ainv;
 | 
|---|
| 110 |         cout << " (93)  mxx = A*Ainv done ---" << endl;
 | 
|---|
| 111 |         PrtTim(" (93) -- ");
 | 
|---|
| 112 |       }
 | 
|---|
| 113 |     }
 | 
|---|
| 114 |   }
 | 
|---|
| 115 |   catch (std::exception & sex) {
 | 
|---|
| 116 |     cerr << " mtxclhep/ catched std::exception what()=" << sex.what() << endl;
 | 
|---|
| 117 |   }  
 | 
|---|
| 118 |   catch (...) {
 | 
|---|
| 119 |     cerr << " mtxclhep/catched unknown (...) exception " << endl; 
 | 
|---|
| 120 |   }  
 | 
|---|
| 121 |   cout << " ------ FIN mtxclhep -------- " << endl;
 | 
|---|
| 122 |   return 0;
 | 
|---|
| 123 | }
 | 
|---|