home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / B < prev    next >
Encoding:
Text File  |  1992-04-14  |  21.0 KB  |  897 lines

  1. /*
  2.  
  3. Translated to C by Bonnie Toy 5/88
  4.  
  5. To compile single precision version for Sun-4:
  6.  
  7.     cc -DSP -O4 -fsingle -fsingle2 clinpack.c -lm
  8.  
  9. To compile double precision version for Sun-4:
  10.  
  11.     cc -DDP -O4 clinpack.c -lm
  12.  
  13. To obtain rolled source BLAS, add -DROLL to the command lines.
  14. To obtain unrolled source BLAS, add -DUNROLL to the command lines.
  15.  
  16. You must specify one of -DSP or -DDP to compile correctly.
  17.  
  18. You must specify one of -DROLL or -DUNROLL to compile correctly.
  19.  
  20. */
  21.  
  22. #ifdef SP
  23. #define REAL float
  24. #define ZERO 0.0
  25. #define ONE 1.0
  26. #define PREC "Single "
  27. #endif
  28.  
  29. #ifdef DP
  30. #define REAL double
  31. #define ZERO 0.0e0
  32. #define ONE 1.0e0
  33. #define PREC "Double "
  34. #endif
  35.  
  36. #define NTIMES 2 
  37.  
  38. #ifdef ROLL
  39. #define ROLLING "Rolled "
  40. #endif
  41. #ifdef UNROLL
  42. #define ROLLING "Unrolled "
  43. #endif
  44.  
  45. #include <stdio.h>
  46. #include <math.h>
  47.  
  48. static REAL Time[8][6];
  49.  
  50. /* bs: change stdout to stdout */
  51.  
  52. main ()
  53. {
  54.     static REAL aa[200][200],a[200][201],b[200],x[200];
  55.     REAL cray,ops,total,norma,normx;
  56.     REAL resid,residn,eps,t1,tm,tm2;
  57.     REAL epslon(),second(),kf;
  58.     static int ipvt[200],n,i,ntimes,info,lda,ldaa,kflops;
  59.  
  60.     lda = 201;
  61.     ldaa = 200;
  62.     cray = .056; 
  63.     n = 100;
  64.  
  65.     fprintf(stdout,ROLLING);fprintf(stdout,PREC);fprintf(stdout,"Precision Linpack\n\n");
  66.  
  67.         ops = (2.0e0*(n*n*n))/3.0 + 2.0*(n*n);
  68.  
  69.         matgen(a,lda,n,b,&norma);
  70.         t1 = second();
  71.         dgefa(a,lda,n,ipvt,&info);
  72.         Time[0][0] = second() - t1;
  73.         t1 = second();
  74.         dgesl(a,lda,n,ipvt,b,0);
  75.         Time[1][0] = second() - t1;
  76.         total = Time[0][0] + Time[1][0];
  77.  
  78. /*     compute a residual to verify results.  */ 
  79.  
  80.         for (i = 0; i < n; i++) {
  81.                 x[i] = b[i];
  82.     }
  83.         matgen(a,lda,n,b,&norma);
  84.         for (i = 0; i < n; i++) {
  85.                 b[i] = -b[i];
  86.     }
  87.         dmxpy(n,b,n,lda,x,a);
  88.         resid = 0.0;
  89.         normx = 0.0;
  90.         for (i = 0; i < n; i++) {
  91.                 resid = (resid > fabs((double)b[i])) 
  92.             ? resid : fabs((double)b[i]);
  93.                 normx = (normx > fabs((double)x[i])) 
  94.             ? normx : fabs((double)x[i]);
  95.     }
  96.         eps = epslon((REAL)ONE);
  97.         residn = resid/( n*norma*normx*eps );
  98.     
  99.        printf("     norm. resid      resid           machep");
  100.         printf("         x[0]-1        x[n-1]-1\n");
  101.     printf("  %8.1f      %16.8e%16.8e%16.8e%16.8e\n",
  102.            (double)residn, (double)resid, (double)eps, 
  103.                (double)x[0]-1, (double)x[n-1]-1);
  104.  
  105.        fprintf(stdout,"    times are reported for matrices of order %5d\n",n);
  106.     fprintf(stdout,"      dgefa      dgesl      total       kflops     unit");
  107.     fprintf(stdout,"      ratio\n");
  108.  
  109.         Time[2][0] = total;
  110.         Time[3][0] = ops/(1.0e3*total);
  111.         Time[4][0] = 2.0e3/Time[3][0];
  112.         Time[5][0] = total/cray;
  113.  
  114.        fprintf(stdout," times for array with leading dimension of%5d\n",lda);
  115.     print_time(0);
  116.  
  117.         matgen(a,lda,n,b,&norma);
  118.         t1 = second();
  119.         dgefa(a,lda,n,ipvt,&info);
  120.         Time[0][1] = second() - t1;
  121.         t1 = second();
  122.         dgesl(a,lda,n,ipvt,b,0);
  123.         Time[1][1] = second() - t1;
  124.         total = Time[0][1] + Time[1][1];
  125.         Time[2][1] = total;
  126.         Time[3][1] = ops/(1.0e3*total);
  127.         Time[4][1] = 2.0e3/Time[3][1];
  128.         Time[5][1] = total/cray;
  129.  
  130.         matgen(a,lda,n,b,&norma);
  131.         t1 = second();
  132.         dgefa(a,lda,n,ipvt,&info);
  133.         Time[0][2] = second() - t1;
  134.         t1 = second();
  135.         dgesl(a,lda,n,ipvt,b,0);
  136.         Time[1][2] = second() - t1;
  137.         total = Time[0][2] + Time[1][2];
  138.         Time[2][2] = total;
  139.         Time[3][2] = ops/(1.0e3*total);
  140.         Time[4][2] = 2.0e3/Time[3][2];
  141.         Time[5][2] = total/cray;
  142.  
  143.         ntimes = NTIMES;
  144.         tm2 = 0.0;
  145.         t1 = second();
  146.  
  147.     for (i = 0; i < ntimes; i++) {
  148.                 tm = second();
  149.         matgen(a,lda,n,b,&norma);
  150.         tm2 = tm2 + second() - tm;
  151.         dgefa(a,lda,n,ipvt,&info);
  152.     }
  153.  
  154.         Time[0][3] = (second() - t1 - tm2)/ntimes;
  155.         t1 = second();
  156.  
  157.     for (i = 0; i < ntimes; i++) {
  158.                 dgesl(a,lda,n,ipvt,b,0);
  159.     }
  160.  
  161.         Time[1][3] = (second() - t1)/ntimes;
  162.         total = Time[0][3] + Time[1][3];
  163.         Time[2][3] = total;
  164.         Time[3][3] = ops/(1.0e3*total);
  165.         Time[4][3] = 2.0e3/Time[3][3];
  166.         Time[5][3] = total/cray;
  167.  
  168.     print_time(1);
  169.     print_time(2);
  170.     print_time(3);
  171.  
  172.         matgen(aa,ldaa,n,b,&norma);
  173.         t1 = second();
  174.         dgefa(aa,ldaa,n,ipvt,&info);
  175.         Time[0][4] = second() - t1;
  176.         t1 = second();
  177.         dgesl(aa,ldaa,n,ipvt,b,0);
  178.         Time[1][4] = second() - t1;
  179.         total = Time[0][4] + Time[1][4];
  180.         Time[2][4] = total;
  181.         Time[3][4] = ops/(1.0e3*total);
  182.         Time[4][4] = 2.0e3/Time[3][4];
  183.         Time[5][4] = total/cray;
  184.  
  185.         matgen(aa,ldaa,n,b,&norma);
  186.         t1 = second();
  187.         dgefa(aa,ldaa,n,ipvt,&info);
  188.         Time[0][5] = second() - t1;
  189.         t1 = second();
  190.         dgesl(aa,ldaa,n,ipvt,b,0);
  191.         Time[1][5] = second() - t1;
  192.         total = Time[0][5] + Time[1][5];
  193.         Time[2][5] = total;
  194.         Time[3][5] = ops/(1.0e3*total);
  195.         Time[4][5] = 2.0e3/Time[3][5];
  196.         Time[5][5] = total/cray;
  197.  
  198.     matgen(aa,ldaa,n,b,&norma);
  199.     t1 = second();
  200.     dgefa(aa,ldaa,n,ipvt,&info);
  201.     Time[0][6] = second() - t1;
  202.     t1 = second();
  203.     dgesl(aa,ldaa,n,ipvt,b,0);
  204.     Time[1][6] = second() - t1;
  205.     total = Time[0][6] + Time[1][6];
  206.     Time[2][6] = total;
  207.     Time[3][6] = ops/(1.0e3*total);
  208.     Time[4][6] = 2.0e3/Time[3][6];
  209.     Time[5][6] = total/cray;
  210.  
  211.     ntimes = NTIMES;
  212.     tm2 = 0;
  213.     t1 = second();
  214.     for (i = 0; i < ntimes; i++) {
  215.         tm = second();
  216.         matgen(aa,ldaa,n,b,&norma);
  217.         tm2 = tm2 + second() - tm;
  218.         dgefa(aa,ldaa,n,ipvt,&info);
  219.     }
  220.     Time[0][7] = (second() - t1 - tm2)/ntimes;
  221.     t1 = second();
  222.     for (i = 0; i < ntimes; i++) {
  223.         dgesl(aa,ldaa,n,ipvt,b,0);
  224.     }
  225.     Time[1][7] = (second() - t1)/ntimes;
  226.     total = Time[0][7] + Time[1][7];
  227.     Time[2][7] = total;
  228.     Time[3][7] = ops/(1.0e3*total);
  229.     Time[4][7] = 2.0e3/Time[3][7];
  230.     Time[5][7] = total/cray;
  231.  
  232.     /* the following code sequence implements the semantics of
  233.        the Fortran intrinsics "nint(min(Time[3][3],Time[3][7]))"    */
  234.  
  235.     kf = (Time[3][3] < Time[3][7]) ? Time[3][3] : Time[3][7];
  236.     kf = (kf > ZERO) ? (kf + .5) : (kf - .5);
  237.     if (fabs((double)kf) < ONE) 
  238.         kflops = 0;
  239.     else {
  240.         kflops = floor(fabs((double)kf));
  241.         if (kf < ZERO) kflops = -kflops;
  242.     }
  243.  
  244.     fprintf(stdout," times for array with leading dimension of%4d\n",ldaa);
  245.     print_time(4);
  246.     print_time(5);
  247.     print_time(6);
  248.     print_time(7);
  249.     fprintf(stdout,ROLLING);fprintf(stdout,PREC);
  250.     fprintf(stdout," Precision %5d Kflops ; %d Reps \n",kflops,NTIMES);
  251.     exit (0);    /* bs: added to make makefile works */
  252. }
  253.      
  254. /*----------------------*/ 
  255. print_time (row)
  256. int row;
  257. {
  258. fprintf(stdout,"%11.2f%11.2f%11.2f%11.0f%11.2f%11.2f\n",   (double)Time[0][row],
  259.        (double)Time[1][row], (double)Time[2][row], (double)Time[3][row], 
  260.        (double)Time[4][row], (double)Time[5][row]);
  261. }
  262.       
  263. /*----------------------*/ 
  264. matgen(a,lda,n,b,norma)
  265. REAL a[],b[],*norma;
  266. int lda, n;
  267.  
  268. /* We would like to declare a[][lda], but c does not allow it.  In this
  269. function, references to a[i][j] are written a[lda*i+j].  */
  270.  
  271. {
  272.     int init, i, j;
  273.  
  274.     init = 1325;
  275.     *norma = 0.0;
  276.     for (j = 0; j < n; j++) {
  277.         for (i = 0; i < n; i++) {
  278.             init = 3125*init % 65536;
  279.             a[lda*j+i] = (init - 32768.0)/16384.0;
  280.             *norma = (a[lda*j+i] > *norma) ? a[lda*j+i] : *norma;
  281.         }
  282.     }
  283.     for (i = 0; i < n; i++) {
  284.           b[i] = 0.0;
  285.     }
  286.     for (j = 0; j < n; j++) {
  287.         for (i = 0; i < n; i++) {
  288.             b[i] = b[i] + a[lda*j+i];
  289.         }
  290.     }
  291. }
  292.  
  293. /*----------------------*/ 
  294. dgefa(a,lda,n,ipvt,info)
  295. REAL a[];
  296. int lda,n,ipvt[],*info;
  297.  
  298. /* We would like to declare a[][lda], but c does not allow it.  In this
  299. function, references to a[i][j] are written a[lda*i+j].  */
  300. /*
  301.      dgefa factors a double precision matrix by gaussian elimination.
  302.  
  303.      dgefa is usually called by dgeco, but it can be called
  304.      directly with a saving in time if  rcond  is not needed.
  305.      (time for dgeco) = (1 + 9/n)*(time for dgefa) .
  306.  
  307.      on entry
  308.  
  309.         a       REAL precision[n][lda]
  310.                 the matrix to be factored.
  311.  
  312.         lda     integer
  313.                 the leading dimension of the array  a .
  314.  
  315.         n       integer
  316.                 the order of the matrix  a .
  317.  
  318.      on return
  319.  
  320.         a       an upper triangular matrix and the multipliers
  321.                 which were used to obtain it.
  322.                 the factorization can be written  a = l*u  where
  323.                 l  is a product of permutation and unit lower
  324.                 triangular matrices and  u  is upper triangular.
  325.  
  326.         ipvt    integer[n]
  327.                 an integer vector of pivot indices.
  328.  
  329.         info    integer
  330.                 = 0  normal value.
  331.                 = k  if  u[k][k] .eq. 0.0 .  this is not an error
  332.                      condition for this subroutine, but it does
  333.                      indicate that dgesl or dgedi will divide by zero
  334.                      if called.  use  rcond  in dgeco for a reliable
  335.                      indication of singularity.
  336.  
  337.      linpack. this version dated 08/14/78 .
  338.      cleve moler, university of new mexico, argonne national lab.
  339.  
  340.      functions
  341.  
  342.      blas daxpy,dscal,idamax
  343. */
  344.  
  345. {
  346. /*     internal variables    */
  347.  
  348. REAL t;
  349. int idamax(),j,k,kp1,l,nm1;
  350.  
  351.  
  352. /*     gaussian elimination with partial pivoting    */
  353.  
  354.     *info = 0;
  355.     nm1 = n - 1;
  356.     if (nm1 >=  0) {
  357.         for (k = 0; k < nm1; k++) {
  358.             kp1 = k + 1;
  359.  
  360.                   /* find l = pivot index    */
  361.  
  362.             l = idamax(n-k,&a[lda*k+k],1) + k;
  363.             ipvt[k] = l;
  364.  
  365.             /* zero pivot implies this column already 
  366.                triangularized */
  367.  
  368.             if (a[lda*k+l] != ZERO) {
  369.  
  370.                 /* interchange if necessary */
  371.  
  372.                 if (l != k) {
  373.                     t = a[lda*k+l];
  374.                     a[lda*k+l] = a[lda*k+k];
  375.                     a[lda*k+k] = t; 
  376.                 }
  377.  
  378.                 /* compute multipliers */
  379.  
  380.                 t = -ONE/a[lda*k+k];
  381.                 dscal(n-(k+1),t,&a[lda*k+k+1],1);
  382.  
  383.                 /* row elimination with column indexing */
  384.  
  385.                 for (j = kp1; j < n; j++) {
  386.                     t = a[lda*j+l];
  387.                     if (l != k) {
  388.                         a[lda*j+l] = a[lda*j+k];
  389.                         a[lda*j+k] = t;
  390.                     }
  391.                     daxpy(n-(k+1),t,&a[lda*k+k+1],1,
  392.                           &a[lda*j+k+1],1);
  393.                   } 
  394.               }
  395.             else { 
  396.                         *info = k;
  397.             }
  398.         } 
  399.     }
  400.     ipvt[n-1] = n-1;
  401.     if (a[lda*(n-1)+(n-1)] == ZERO) *info = n-1;
  402. }
  403.  
  404. /*----------------------*/ 
  405.  
  406. dgesl(a,lda,n,ipvt,b,job)
  407. int lda,n,ipvt[],job;
  408. REAL a[],b[];
  409.  
  410. /* We would like to declare a[][lda], but c does not allow it.  In this
  411. function, references to a[i][j] are written a[lda*i+j].  */
  412.  
  413. /*
  414.      dgesl solves the double precision system
  415.      a * x = b  or  trans(a) * x = b
  416.      using the factors computed by dgeco or dgefa.
  417.  
  418.      on entry
  419.  
  420.         a       double precision[n][lda]
  421.                 the output from dgeco or dgefa.
  422.  
  423.         lda     integer
  424.                 the leading dimension of the array  a .
  425.  
  426.         n       integer
  427.                 the order of the matrix  a .
  428.  
  429.         ipvt    integer[n]
  430.                 the pivot vector from dgeco or dgefa.
  431.  
  432.         b       double precision[n]
  433.                 the right hand side vector.
  434.  
  435.         job     integer
  436.                 = 0         to solve  a*x = b ,
  437.                 = nonzero   to solve  trans(a)*x = b  where
  438.                             trans(a)  is the transpose.
  439.  
  440.     on return
  441.  
  442.         b       the solution vector  x .
  443.  
  444.      error condition
  445.  
  446.         a division by zero will occur if the input factor contains a
  447.         zero on the diagonal.  technically this indicates singularity
  448.         but it is often caused by improper arguments or improper
  449.         setting of lda .  it will not occur if the subroutines are
  450.         called correctly and if dgeco has set rcond .gt. 0.0
  451.         or dgefa has set info .eq. 0 .
  452.  
  453.      to compute  inverse(a) * c  where  c  is a matrix
  454.      with  p  columns
  455.            dgeco(a,lda,n,ipvt,rcond,z)
  456.            if (!rcond is too small){
  457.                for (j=0,j<p,j++)
  458.                       dgesl(a,lda,n,ipvt,c[j][0],0);
  459.        }
  460.  
  461.      linpack. this version dated 08/14/78 .
  462.      cleve moler, university of new mexico, argonne national lab.
  463.  
  464.      functions
  465.  
  466.      blas daxpy,ddot
  467. */
  468. {
  469. /*     internal variables    */
  470.  
  471.     REAL ddot(),t;
  472.     int k,kb,l,nm1;
  473.  
  474.     nm1 = n - 1;
  475.     if (job == 0) {
  476.  
  477.         /* job = 0 , solve  a * x = b
  478.            first solve  l*y = b        */
  479.  
  480.         if (nm1 >= 1) {
  481.             for (k = 0; k < nm1; k++) {
  482.                 l = ipvt[k];
  483.                 t = b[l];
  484.                 if (l != k){ 
  485.                     b[l] = b[k];
  486.                     b[k] = t;
  487.                 }    
  488.                 daxpy(n-(k+1),t,&a[lda*k+k+1],1,&b[k+1],1);
  489.             }
  490.         } 
  491.  
  492.         /* now solve  u*x = y */
  493.  
  494.         for (kb = 0; kb < n; kb++) {
  495.             k = n - (kb + 1);
  496.             b[k] = b[k]/a[lda*k+k];
  497.             t = -b[k];
  498.             daxpy(k,t,&a[lda*k+0],1,&b[0],1);
  499.         }
  500.     }
  501.     else { 
  502.  
  503.         /* job = nonzero, solve  trans(a) * x = b
  504.            first solve  trans(u)*y = b             */
  505.  
  506.         for (k = 0; k < n; k++) {
  507.             t = ddot(k,&a[lda*k+0],1,&b[0],1);
  508.             b[k] = (b[k] - t)/a[lda*k+k];
  509.         }
  510.  
  511.         /* now solve trans(l)*x = y    */
  512.  
  513.         if (nm1 >= 1) {
  514.             for (kb = 1; kb < nm1; kb++) {
  515.                 k = n - (kb+1);
  516.                 b[k] = b[k] + ddot(n-(k+1),&a[lda*k+k+1],1,&b[k+1],1);
  517.                 l = ipvt[k];
  518.                 if (l != k) {
  519.                     t = b[l];
  520.                     b[l] = b[k];
  521.                     b[k] = t;
  522.                 }
  523.             }
  524.         }
  525.     }
  526. }
  527.  
  528. /*----------------------*/ 
  529.  
  530. daxpy(n,da,dx,incx,dy,incy)
  531. /*
  532.      constant times a vector plus a vector.
  533.      jack dongarra, linpack, 3/11/78.
  534. */
  535. REAL dx[],dy[],da;
  536. int incx,incy,n;
  537. {
  538.     int i,ix,iy,m,mp1;
  539.  
  540.     if(n <= 0) return;
  541.     if (da == ZERO) return;
  542.  
  543.     if(incx != 1 || incy != 1) {
  544.  
  545.         /* code for unequal increments or equal increments
  546.            not equal to 1                     */
  547.  
  548.         ix = 1;
  549.         iy = 1;
  550.         if(incx < 0) ix = (-n+1)*incx + 1;
  551.         if(incy < 0)iy = (-n+1)*incy + 1;
  552.         for (i = 0;i < n; i++) {
  553.             dy[iy] = dy[iy] + da*dx[ix];
  554.             ix = ix + incx;
  555.             iy = iy + incy;
  556.         }
  557.               return;
  558.     }
  559.  
  560.     /* code for both increments equal to 1 */
  561.  
  562. #ifdef ROLL
  563.     for (i = 0;i < n; i++) {
  564.         dy[i] = dy[i] + da*dx[i];
  565.     }
  566. #endif
  567. #ifdef UNROLL
  568.  
  569.     m = n % 4;
  570.     if ( m != 0) {
  571.         for (i = 0; i < m; i++) 
  572.             dy[i] = dy[i] + da*dx[i];
  573.         if (n < 4) return;
  574.     }
  575.     for (i = m; i < n; i = i + 4) {
  576.         dy[i] = dy[i] + da*dx[i];
  577.         dy[i+1] = dy[i+1] + da*dx[i+1];
  578.         dy[i+2] = dy[i+2] + da*dx[i+2];
  579.         dy[i+3] = dy[i+3] + da*dx[i+3];
  580.     }
  581. #endif
  582. }
  583.    
  584. /*----------------------*/ 
  585.  
  586. REAL ddot(n,dx,incx,dy,incy)
  587. /*
  588.      forms the dot product of two vectors.
  589.      jack dongarra, linpack, 3/11/78.
  590. */
  591. REAL dx[],dy[];
  592.  
  593. int incx,incy,n;
  594. {
  595.     REAL dtemp;
  596.     int i,ix,iy,m,mp1;
  597.  
  598.     dtemp = ZERO;
  599.  
  600.     if(n <= 0) return(ZERO);
  601.  
  602.     if(incx != 1 || incy != 1) {
  603.  
  604.         /* code for unequal increments or equal increments
  605.            not equal to 1                    */
  606.  
  607.         ix = 0;
  608.         iy = 0;
  609.         if (incx < 0) ix = (-n+1)*incx;
  610.         if (incy < 0) iy = (-n+1)*incy;
  611.         for (i = 0;i < n; i++) {
  612.             dtemp = dtemp + dx[ix]*dy[iy];
  613.             ix = ix + incx;
  614.             iy = iy + incy;
  615.         }
  616.         return(dtemp);
  617.     }
  618.  
  619.     /* code for both increments equal to 1 */
  620.  
  621. #ifdef ROLL
  622.     for (i=0;i < n; i++)
  623.         dtemp = dtemp + dx[i]*dy[i];
  624.     return(dtemp);
  625. #endif
  626. #ifdef UNROLL
  627.  
  628.     m = n % 5;
  629.     if (m != 0) {
  630.         for (i = 0; i < m; i++)
  631.             dtemp = dtemp + dx[i]*dy[i];
  632.         if (n < 5) return(dtemp);
  633.     }
  634.     for (i = m; i < n; i = i + 5) {
  635.         dtemp = dtemp + dx[i]*dy[i] +
  636.         dx[i+1]*dy[i+1] + dx[i+2]*dy[i+2] +
  637.         dx[i+3]*dy[i+3] + dx[i+4]*dy[i+4];
  638.     }
  639.     return(dtemp);
  640. #endif
  641. }
  642.  
  643. /*----------------------*/ 
  644. dscal(n,da,dx,incx)
  645.  
  646. /*     scales a vector by a constant.
  647.       jack dongarra, linpack, 3/11/78.
  648. */
  649. REAL da,dx[];
  650. int n, incx;
  651. {
  652.     int i,m,mp1,nincx;
  653.  
  654.     if(n <= 0)return;
  655.     if(incx != 1) {
  656.  
  657.         /* code for increment not equal to 1 */
  658.  
  659.         nincx = n*incx;
  660.         for (i = 0; i < nincx; i = i + incx)
  661.             dx[i] = da*dx[i];
  662.         return;
  663.     }
  664.  
  665.     /* code for increment equal to 1 */
  666.  
  667. #ifdef ROLL
  668.     for (i = 0; i < n; i++)
  669.         dx[i] = da*dx[i];
  670. #endif
  671. #ifdef UNROLL
  672.  
  673.     m = n % 5;
  674.     if (m != 0) {
  675.         for (i = 0; i < m; i++)
  676.             dx[i] = da*dx[i];
  677.         if (n < 5) return;
  678.     }
  679.     for (i = m; i < n; i = i + 5){
  680.         dx[i] = da*dx[i];
  681.         dx[i+1] = da*dx[i+1];
  682.         dx[i+2] = da*dx[i+2];
  683.         dx[i+3] = da*dx[i+3];
  684.         dx[i+4] = da*dx[i+4];
  685.     }
  686. #endif
  687.  
  688. }
  689.  
  690. /*----------------------*/ 
  691. int idamax(n,dx,incx)
  692.  
  693. /*
  694.      finds the index of element having max. absolute value.
  695.      jack dongarra, linpack, 3/11/78.
  696. */
  697.  
  698. REAL dx[];
  699. int incx,n;
  700. {
  701.     REAL dmax;
  702.     int i, ix, itemp;
  703.  
  704.     if( n < 1 ) return(-1);
  705.     if(n ==1 ) return(0);
  706.     if(incx != 1) {
  707.  
  708.         /* code for increment not equal to 1 */
  709.  
  710.         ix = 1;
  711.         dmax = fabs((double)dx[0]);
  712.         ix = ix + incx;
  713.         for (i = 1; i < n; i++) {
  714.             if(fabs((double)dx[ix]) > dmax)  {
  715.                 itemp = i;
  716.                 dmax = fabs((double)dx[ix]);
  717.             }
  718.             ix = ix + incx;
  719.         }
  720.     }
  721.     else {
  722.  
  723.         /* code for increment equal to 1 */
  724.  
  725.         itemp = 0;
  726.         dmax = fabs((double)dx[0]);
  727.         for (i = 1; i < n; i++) {
  728.             if(fabs((double)dx[i]) > dmax) {
  729.                 itemp = i;
  730.                 dmax = fabs((double)dx[i]);
  731.             }
  732.         }
  733.     }
  734.     return (itemp);
  735. }
  736.  
  737. /*----------------------*/ 
  738. REAL epslon (x)
  739. REAL x;
  740. /*
  741.      estimate unit roundoff in quantities of size x.
  742. */
  743.  
  744. {
  745.     REAL a,b,c,eps;
  746. /*
  747.      this program should function properly on all systems
  748.      satisfying the following two assumptions,
  749.         1.  the base used in representing dfloating point
  750.             numbers is not a power of three.
  751.         2.  the quantity  a  in statement 10 is represented to 
  752.             the accuracy used in dfloating point variables
  753.             that are stored in memory.
  754.      the statement number 10 and the go to 10 are intended to
  755.      force optimizing compilers to generate code satisfying 
  756.      assumption 2.
  757.      under these assumptions, it should be true that,
  758.             a  is not exactly equal to four-thirds,
  759.             b  has a zero for its last bit or digit,
  760.             c  is not exactly equal to one,
  761.             eps  measures the separation of 1.0 from
  762.                  the next larger dfloating point number.
  763.      the developers of eispack would appreciate being informed
  764.      about any systems where these assumptions do not hold.
  765.  
  766.      *****************************************************************
  767.      this routine is one of the auxiliary routines used by eispack iii
  768.      to avoid machine dependencies.
  769.      *****************************************************************
  770.  
  771.      this version dated 4/6/83.
  772. */
  773.  
  774.     a = 4.0e0/3.0e0;
  775.     eps = ZERO;
  776.     while (eps == ZERO) {
  777.         b = a - ONE;
  778.         c = b + b + b;
  779.         eps = fabs((double)(c-ONE));
  780.     }
  781.     return(eps*fabs((double)x));
  782. }
  783.  
  784. /*----------------------*/ 
  785. dmxpy (n1, y, n2, ldm, x, m)
  786. REAL y[], x[], m[];
  787. int n1, n2, ldm;
  788.  
  789. /* We would like to declare m[][ldm], but c does not allow it.  In this
  790. function, references to m[i][j] are written m[ldm*i+j].  */
  791.  
  792. /*
  793.    purpose:
  794.      multiply matrix m times vector x and add the result to vector y.
  795.  
  796.    parameters:
  797.  
  798.      n1 integer, number of elements in vector y, and number of rows in
  799.          matrix m
  800.  
  801.      y double [n1], vector of length n1 to which is added 
  802.          the product m*x
  803.  
  804.      n2 integer, number of elements in vector x, and number of columns
  805.          in matrix m
  806.  
  807.      ldm integer, leading dimension of array m
  808.  
  809.      x double [n2], vector of length n2
  810.  
  811.      m double [ldm][n2], matrix of n1 rows and n2 columns
  812.  
  813.  ----------------------------------------------------------------------
  814. */
  815. {
  816.     int j,i,jmin;
  817.     /* cleanup odd vector */
  818.  
  819.     j = n2 % 2;
  820.     if (j >= 1) {
  821.         j = j - 1;
  822.         for (i = 0; i < n1; i++) 
  823.                     y[i] = (y[i]) + x[j]*m[ldm*j+i];
  824.     } 
  825.  
  826.     /* cleanup odd group of two vectors */
  827.  
  828.     j = n2 % 4;
  829.     if (j >= 2) {
  830.         j = j - 1;
  831.         for (i = 0; i < n1; i++)
  832.                     y[i] = ( (y[i])
  833.                              + x[j-1]*m[ldm*(j-1)+i]) + x[j]*m[ldm*j+i];
  834.     } 
  835.  
  836.     /* cleanup odd group of four vectors */
  837.  
  838.     j = n2 % 8;
  839.     if (j >= 4) {
  840.         j = j - 1;
  841.         for (i = 0; i < n1; i++)
  842.             y[i] = ((( (y[i])
  843.                    + x[j-3]*m[ldm*(j-3)+i]) 
  844.                    + x[j-2]*m[ldm*(j-2)+i])
  845.                    + x[j-1]*m[ldm*(j-1)+i]) + x[j]*m[ldm*j+i];
  846.     } 
  847.  
  848.     /* cleanup odd group of eight vectors */
  849.  
  850.     j = n2 % 16;
  851.     if (j >= 8) {
  852.         j = j - 1;
  853.         for (i = 0; i < n1; i++)
  854.             y[i] = ((((((( (y[i])
  855.                    + x[j-7]*m[ldm*(j-7)+i]) + x[j-6]*m[ldm*(j-6)+i])
  856.                      + x[j-5]*m[ldm*(j-5)+i]) + x[j-4]*m[ldm*(j-4)+i])
  857.                    + x[j-3]*m[ldm*(j-3)+i]) + x[j-2]*m[ldm*(j-2)+i])
  858.                    + x[j-1]*m[ldm*(j-1)+i]) + x[j]  *m[ldm*j+i];
  859.     } 
  860.     
  861.     /* main loop - groups of sixteen vectors */
  862.  
  863.     jmin = (n2%16)+16;
  864.     for (j = jmin-1; j < n2; j = j + 16) {
  865.         for (i = 0; i < n1; i++) 
  866.             y[i] = ((((((((((((((( (y[i])
  867.                        + x[j-15]*m[ldm*(j-15)+i]) 
  868.                 + x[j-14]*m[ldm*(j-14)+i])
  869.                     + x[j-13]*m[ldm*(j-13)+i]) 
  870.                 + x[j-12]*m[ldm*(j-12)+i])
  871.                     + x[j-11]*m[ldm*(j-11)+i]) 
  872.                 + x[j-10]*m[ldm*(j-10)+i])
  873.                     + x[j- 9]*m[ldm*(j- 9)+i]) 
  874.                 + x[j- 8]*m[ldm*(j- 8)+i])
  875.                     + x[j- 7]*m[ldm*(j- 7)+i]) 
  876.                 + x[j- 6]*m[ldm*(j- 6)+i])
  877.                     + x[j- 5]*m[ldm*(j- 5)+i]) 
  878.                 + x[j- 4]*m[ldm*(j- 4)+i])
  879.                     + x[j- 3]*m[ldm*(j- 3)+i]) 
  880.                 + x[j- 2]*m[ldm*(j- 2)+i])
  881.                     + x[j- 1]*m[ldm*(j- 1)+i]) 
  882.                 + x[j]   *m[ldm*j+i];
  883.     }
  884.  
  885.  
  886.  
  887. #include <time.h>
  888.  
  889. REAL second()
  890. {
  891. return (REAL)(((double)(clock()))/((double)(CLOCKS_PER_SEC))) ;
  892. }
  893.  
  894.  
  895.  
  896.