| 1 | #include "machdefs.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <math.h> | 
|---|
| 4 | #include <iostream.h> | 
|---|
| 5 |  | 
|---|
| 6 | #include "srandgen.h" | 
|---|
| 7 | #include "tarrinit.h" | 
|---|
| 8 | #include "array.h" | 
|---|
| 9 | #include "timing.h" | 
|---|
| 10 | #include "intflapack.h" | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | void lpk_tarr(int n); | 
|---|
| 14 | void lpk_tmtx(int n); | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | int main(int narg, char* arg[]) | 
|---|
| 18 | { | 
|---|
| 19 |  | 
|---|
| 20 | SophyaInit(); | 
|---|
| 21 | InitTim();   // Initializing the CPU timer | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | if (narg < 2) { | 
|---|
| 26 | cout << " lpk - LinAlg/LapackServer test - Usage lpk t/s [size=5] [prtlev=0] [nprtmax=100]\n" | 
|---|
| 27 | << " t:  lpk_tarr() rztest_lapack with TArray<r_4> \n" | 
|---|
| 28 | << " s:  lpk_tmtx() LapackServer with TMatrix<r_8> \n" << endl; | 
|---|
| 29 | exit(0); | 
|---|
| 30 | } | 
|---|
| 31 | int n = 5; | 
|---|
| 32 | int opt = 's'; | 
|---|
| 33 | opt = *(arg[1]); | 
|---|
| 34 | if (narg > 2) n = atoi(arg[2]); | 
|---|
| 35 | int nprt = 100; | 
|---|
| 36 | int prtlev = 1; | 
|---|
| 37 | if (narg > 3) prtlev = atoi(arg[3]); | 
|---|
| 38 | if (narg > 4) nprt = atoi(arg[4]); | 
|---|
| 39 |  | 
|---|
| 40 | BaseArray::SetMaxPrint(nprt, prtlev); | 
|---|
| 41 | try { | 
|---|
| 42 | if (opt == 's') lpk_tmtx(n); | 
|---|
| 43 | else lpk_tarr(n); | 
|---|
| 44 | } | 
|---|
| 45 | catch (PThrowable exc) { | 
|---|
| 46 | cerr << " catched Exception (lpk.cc) " << exc.Msg() << endl; | 
|---|
| 47 | } | 
|---|
| 48 | catch (...) { | 
|---|
| 49 | cerr << " catched unknown (...) exception (lpk.cc) " << endl; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | PrtTim(" End of lpk LinAlg/Lapack test "); | 
|---|
| 53 | cout << " ---------------  END of Programme -------------- " << endl; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 |  | 
|---|
| 57 | void lpk_tmtx(int n) | 
|---|
| 58 | { | 
|---|
| 59 | int i,j,k; | 
|---|
| 60 | BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping); | 
|---|
| 61 | Matrix a(n,n); | 
|---|
| 62 | for(i=0; i<n; i++) | 
|---|
| 63 | for(j=0; j<n; j++)  a(j,i) = GauRnd(0., 1.); | 
|---|
| 64 | cout << " ------------ Matrix A = \n " << a << "\n" << endl; | 
|---|
| 65 |  | 
|---|
| 66 | Vector x(n), b; | 
|---|
| 67 | //  Matrix  x(n,1), b; | 
|---|
| 68 | cout << " ------------ Vector X = \n " << x << "\n" << endl; | 
|---|
| 69 | for(i=0; i<n; i++) x(i) = GauRnd(2., 1.5); | 
|---|
| 70 | b = a*x; | 
|---|
| 71 |  | 
|---|
| 72 | //  cout << ":::::::: rztest_lapack - Size=" << n << "  ::::::::: " << endl; | 
|---|
| 73 | cout << " ------- lpk_tmtx() LapackServerTest Using TMatrix<r_8> -------- " << endl; | 
|---|
| 74 | cout << " ------------ Matrix A = \n " << a << "\n" << endl; | 
|---|
| 75 | cout << " ------------ Matrix X = \n " << x << "\n" << endl; | 
|---|
| 76 | cout << " ------------ Matrix B = \n " << b << "\n" << endl; | 
|---|
| 77 |  | 
|---|
| 78 | cout << "\n   Calling LapackLinSolve(a,b) .... " << endl; | 
|---|
| 79 | PrtTim(" Calling LapackLinSolve(a,b) "); | 
|---|
| 80 | LapackLinSolve(a,b); | 
|---|
| 81 | PrtTim(" End LapackLinSolve(a,b) "); | 
|---|
| 82 |  | 
|---|
| 83 | cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; | 
|---|
| 84 | Vector diff = b-x; | 
|---|
| 85 | cout << " ------------ Vector diff B-X = \n " << diff << "\n" << endl; | 
|---|
| 86 |  | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | void lpk_tarr(int n) | 
|---|
| 90 | { | 
|---|
| 91 | int i,j,k; | 
|---|
| 92 | TArray<r_4> a(n,n); | 
|---|
| 93 | for(i=0; i<n; i++) | 
|---|
| 94 | for(j=0; j<n; j++)  a(i,j,0) = GauRnd(0., 1.); | 
|---|
| 95 |  | 
|---|
| 96 | TArray<r_4> x(n,1), b(n,1); | 
|---|
| 97 | r_4 sum ; | 
|---|
| 98 | for(i=0; i<n; i++) x(i,0,0) = GauRnd(2., 1.5); | 
|---|
| 99 | for(i=0; i<n; i++) { | 
|---|
| 100 | sum = 0.; | 
|---|
| 101 | for(j=0; j<n; j++) sum +=  a(i,j,0)*x(j,0,0); | 
|---|
| 102 | b(i,0,0) = sum; | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | //  cout << ":::::::: rztest_lapack - Size=" << n << "  ::::::::: " << endl; | 
|---|
| 106 | cout << " ------- lpk_tarr() LapaackTest Using TArray<r_4> -------- " << endl; | 
|---|
| 107 | cout << " ------------ Array A = \n " << a << "\n" << endl; | 
|---|
| 108 | cout << " ------------ Array X = \n " << x << "\n" << endl; | 
|---|
| 109 | cout << " ------------ Array B = \n " << b << "\n" << endl; | 
|---|
| 110 |  | 
|---|
| 111 | cout << "\n     Calling rztest_lapack ... " << endl; | 
|---|
| 112 |  | 
|---|
| 113 | rztest_lapack(a, b); | 
|---|
| 114 |  | 
|---|
| 115 | cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; | 
|---|
| 116 | } | 
|---|