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