| [778] | 1 | #include "machdefs.h" | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <math.h> | 
|---|
|  | 4 | #include <iostream.h> | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #include "nbrandom.h" | 
|---|
|  | 7 | #include "tarrinit.h" | 
|---|
|  | 8 | #include "tarray.h" | 
|---|
|  | 9 | #include "tvector.h" | 
|---|
|  | 10 | #include "timing.h" | 
|---|
|  | 11 | #include "intflapack.h" | 
|---|
|  | 12 |  | 
|---|
|  | 13 |  | 
|---|
| [812] | 14 | void lpk_tarr(int n); | 
|---|
|  | 15 | void lpk_tmtx(int n); | 
|---|
|  | 16 |  | 
|---|
| [778] | 17 | int main(int narg, char* arg[]) | 
|---|
|  | 18 | { | 
|---|
|  | 19 |  | 
|---|
|  | 20 | SophyaInit(); | 
|---|
|  | 21 | InitTim();   // Initializing the CPU timer | 
|---|
|  | 22 |  | 
|---|
|  | 23 |  | 
|---|
| [812] | 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 | } | 
|---|
| [778] | 31 | int n = 5; | 
|---|
| [812] | 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 | { | 
|---|
| [778] | 59 | int i,j,k; | 
|---|
| [812] | 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; | 
|---|
| [778] | 71 |  | 
|---|
| [812] | 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 | LapackLinSolve(a,b); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; | 
|---|
|  | 82 | Vector diff = b-x; | 
|---|
|  | 83 | cout << " ------------ Vector diff B-X = \n " << diff << "\n" << endl; | 
|---|
|  | 84 |  | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | void lpk_tarr(int n) | 
|---|
|  | 88 | { | 
|---|
|  | 89 | int i,j,k; | 
|---|
| [778] | 90 | TArray<r_4> a(n,n); | 
|---|
|  | 91 | for(i=0; i<n; i++) | 
|---|
|  | 92 | for(j=0; j<n; j++)  a(i,j,0) = GauRnd(0., 1.); | 
|---|
|  | 93 |  | 
|---|
| [789] | 94 | TArray<r_4> x(n,1), b(n,1); | 
|---|
| [778] | 95 | r_4 sum ; | 
|---|
| [789] | 96 | for(i=0; i<n; i++) x(i,0,0) = GauRnd(2., 1.5); | 
|---|
| [778] | 97 | for(i=0; i<n; i++) { | 
|---|
|  | 98 | sum = 0.; | 
|---|
| [789] | 99 | for(j=0; j<n; j++) sum +=  a(i,j,0)*x(j,0,0); | 
|---|
|  | 100 | b(i,0,0) = sum; | 
|---|
| [778] | 101 | } | 
|---|
|  | 102 |  | 
|---|
| [812] | 103 | //  cout << ":::::::: rztest_lapack - Size=" << n << "  ::::::::: " << endl; | 
|---|
|  | 104 | cout << " ------- lpk_tarr() LapaackTest Using TArray<r_4> -------- " << endl; | 
|---|
| [807] | 105 | cout << " ------------ Array A = \n " << a << "\n" << endl; | 
|---|
|  | 106 | cout << " ------------ Array X = \n " << x << "\n" << endl; | 
|---|
|  | 107 | cout << " ------------ Array B = \n " << b << "\n" << endl; | 
|---|
| [778] | 108 |  | 
|---|
|  | 109 | cout << "\n     Calling rztest_lapack ... " << endl; | 
|---|
|  | 110 |  | 
|---|
|  | 111 | rztest_lapack(a, b); | 
|---|
|  | 112 |  | 
|---|
|  | 113 | cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; | 
|---|
|  | 114 | } | 
|---|