SND@LHC Software
Loading...
Searching...
No Matches
Dbandmatrix.f90 File Reference

Symmetric (band) matrix routines. More...

Go to the source code of this file.

Functions/Subroutines

subroutine dchdec (w, n, aux)
 Decomposition of symmetric matrix.
 
real(mps) function condes (w, n, aux)
 Etimate condition.
 
subroutine dbcdec (w, mp1, n, aux)
 Decomposition of symmetric band matrix.
 
subroutine dbcprv (w, mp1, n, b)
 Print corr band matrix and pars.
 
subroutine dbcprb (w, mp1, n)
 Print band matrix.
 
subroutine db2dec (w, n, aux)
 Decomposition (M=1).
 
subroutine db3dec (w, n, aux)
 Decomposition (M=2).
 
subroutine dcfdec (w, n)
 Decomposition of symmetric matrix.
 
subroutine dbfdec (w, mp1, n)
 Decomposition of symmetric band matrix.
 

Detailed Description

Symmetric (band) matrix routines.

Author
Volker Blobel, University Hamburg, 2005-2009 (initial Fortran77 version)
Claus Kleinwort, DESY (maintenance and developement)

For the original broken lines implementation by V. Blobel (University Hamburg).

    *************************************************************
    *                                                           *
    *   Subroutines for symmetric and symmetric band matrices,  *
    *   based on the (square root free) Cholesky decomposition. *
    *                                                           *
    *************************************************************

    All floating point arguments are in DOUBLE PRECISION (and all
    entry names start with a D).

    The Cholesky decomposition transforms a symmetric matrix W
    e.g. the matrix from normal equation of least squares,
    according to
                          W = L D L^         (L^ means L transposed)
    where D is a diagonal matrix and L is a unit triangular matrix
    (diagonal elements all ones, all elements above diagonal zero).

    The above decomposition allows to solve a matrix equation
                        W x = b
    in two steps, using an auxiliary vector y:

                 solve  L y = b  for y, and

               solve D L^ x = y  for x.

    The inverse matrix of W can be calculated from the decomposition.

    In least-squares normal equations the inverse matrix is equal to
    the covariance matrix of the fitted parameters. All diagonal elements
    of the inverse matrix, the parameter variances, are positive, and
    the matrix is positive-definite (all eigenvalues > 0).

    The Cholesky algorithm is stable for a positive-definite matrix.
    The standard form of the Cholesky algorithm includes n square roots
    for a n-by-n matrix, and is possible only for positive-definite
    matrices. The version used here is squareroot-free; this algorithm
    does not necessarily break down in the indefinite case, although
    it is potentially unstable in this case. All decomposition routines
    include a check for singularity, and this check needs an auxiliary
    array AUX of dimension n.

    Method: The Cholesky algorithm for symmetric matrix decomposition
    makes use of the symmetry. The operation count (leading term)
    is n**3/6 (compared to n**3/3 for normal Gaussian elimination).
    The solution of the two triangular systems involves operations
    proportional to n**2.

    The real advantage of the Cholesky algorithm is for band matrices,
    where all matrix elements outside of a band with total width
    (2m+1) around the diagonal are zero. The band structure is kept
    in the decomposition, and allows a fast solution of matrix equations.
    The operation count (leading term) is proportional to m**2*n
    and thus (for fixed m) linear in n. Thus for n=100 and m=2 the
    Cholesky algorithm for the band matrix is 1000 times faster than
    the standard solution method.

    The inverse of a band matrix is a full matrix. It is not necessary
    to calculate the inverse, if only the solution for a matrix equation
    is needed. However the inverse is often needed, because the elements
    of the inverse are the variances and covariances of parameters in
    a least-squares fit. The inverse can be calculated afterwards from
    the decomposition. Since the inverse matrix is a full matrix, this
    has of course an operation count proportional to n**3.

    Usually only the elements of the inverse in and around the diagonal
    are really needed, and this subset of inverse elements, corresponding
    to the original band, can be calculated from the decomposition with
    an operation count, which is linear in n. Thus all variances (the
    diagonal elements) and covariances between neighbour parameters
    are calculated in a short time even for large matrices.

    Matrix storage: the mathematical indexing of matrix elements follows
    the scheme:

                      (  W11   W12   W13 ... W1n  )
                      (  W21   W22   W23 ... W2n  )
                  W = (  ...   ...   ...     ...  )
                      (  ...   ...   ...     ...  )
                      (  Wn1   Wn2   Wn3 ... Wnn  )

    and a storage in an array would require n**2 words, although the
    symmetric matrix has only (n**2+n)/2 different elements, and a band
    matrix has less than (m+1)*n different elements. Therefore the
    following storage schemes are used.

    Symmetric matrix: the elements are in the order
            W11   W12   W22   W13   W23   W33   W14 ... Wnn
    with total (n**2+n)/2 array elements.

    Band matrix: a band matrix of bandwidth m is stored in an array
    of dimension W(m+1,n), according to

                      W(1,.)    W(2,.)    W(3,.)
                     --------------------------------
                       W11       W12       W13
                       W22       W23       W24
                       W33       W34       W35
                       ...
                       Wnn        -         -

    The example is for a bandwidth of m=2; three elements at the end
    are unused. The diagonal elements are in the array elements W(1,.).

    This package includes subroutines for:

       (1) Symmetric matrix W: decomposition, solution, inverse

       (2) Symmetric band matrix: decomposition, solution, complete
           inverse and band part of the inverse

       (3) Symmetric band matrix of band width m=1: decomposition,
           solution, complete, inverse and band part of the inverse

       (4) Symmetric band matrix of band width m=2: decomposition,
           solution, complete, inverse and band part of the inverse

       (5) Symmetric matrix with band structure, bordered by full row/col
           (not yet included)

    The subroutines for a fixed band width of m=1 and of m=2 are
    faster than the general routine, because certain loops are avoided
    and replaced by the direct code.

    Historical remark: the square-root algorithm was invented by the
    french Mathematician Andre-Louis Cholesky (1875 - 1918).
    Cholesky's method of computing solutions to the normal equations was
    published 1924, after the death of Cholesky, by Benoit.
    The method received little attention after its publication in 1924.
    In 1948 the method was analysed in a paper by Fox, Huskey and
    Wilkinson, and in the same year Turing published a paper on the
    stability of the method.

    The fast method to calculate the band part of the inverse matrix
    is usually not mentioned in the literature. An exception is:
    I.S.Duff, A.M.Erisman and J.K.Reid, Direct Methods for Sparse
    Matrices, Oxford Science Publications, 1986.
    The following original work is quoted in this book:
    K.Takahashi, J.Fagan and M.Chin, Formation of a sparse bus
    impedance matrix and its application to short circuit study.
    Proceedings 8th PICA Conference, Minneapolis, Minnesota, 1973
    A.M.Erisman and W.F.Tinney, On computing certain elements of the
    inverse of a sparse matrix, CACM 18, 177-179, 1975



    symmetric          decomposit. solution    inv-element    inverse
    ----------------  |-----------|-----------|--------------|-----------|
    n x n matrix        DCHDEC      DCHSLV      -              DCHINV
    band matrix m,n     DBCDEC      DBCSLV      DBCIEL/DBCINB  DBCINV
    bandwidth m=1       DB2DEC      DB2SLV      DB2IEL         -
    bandwidth m=2       DB3DEC      DB3SLV      DB3IEL         -

    The DB2... and DB3... routines are special routines for a fixed bandwidth
    of 1 and 2, they are faster versions of the general DBG... routines.
    The complete inverse matrix can be obtained by DBGINV.
    The routine DBGPRI can be used to print all types of band matrices.

    The decomposition in routines ...DEC replaces (overwrites) the
    original matrix (the number of elements is identical). All other
    routines require W to be the already decomposed matrix.
    The matrix L is a unit lower triangular matrix, with ones on the
    diagonal, which have not be stored. Instead the inverse of the
    diagonal elements of matrix D are stored in those places.

    In the  solution routines ...SLV the array B is the right-hand matrix,
    the array is the resulting solution. The same array can be used
    for B and X.


    W(.) and V(.) are symmetric n-by-n matrices with (N*N+N)/2 elements

    SUBROUTINE DCHDEC(W,N, AUX)      ! decomposition, symmetric matrix
         ENTRY DCHSLV(W,N,B, X)      ! solution B -> X
         ENTRY DCHINV(W,N, V)        ! inversion

    SUBROUTINE DCFDEC(W,N)           ! modified composition, symmetric
                                     ! alternative to DCHDEC

    W(.) and V(.) are band matrices, n rows, band width m (i.e. the total
         width of the band is (2m+1).
         With MP1 = m +1, the array has dimension W(MP1,N).
         The symmetric matrix VS has (N*N+N)/2 elements

    SUBROUTINE DBCDEC(W,MP1,N, AUX)  ! decomposition, bandwidth M
         ENTRY DBCSLV(W,MP1,N,B, X)  ! solution B -> X
         ENTRY DBCIEL(W,MP1,N, V)    ! V = inverse band matrix elements
         ENTRY DBCINV(W,MP1,N, VS)   ! V = inverse symmetric matrix

    SUBROUTINE DBFDEC(W,MP1,N)       ! modified decomposition, bandwidth M
                                     ! alternative to DBCDEC

    SUBROUTINE DBCPRB(W,MP1,N)       ! print band matrix
    SUBROUTINE DBCPRV(W,MP1,N,B)     ! print corr band matrix and pars

    SUBROUTINE DB2DEC(W,N, AUX)      ! decomposition (M=1)
         ENTRY DB2SLV(W,N,B, X)      ! solution B -> X
         ENTRY DB2IEL(W,N, V)        ! V = inverse band matrix elements

    SUBROUTINE DB3DEC(W,N, AUX)      ! decomposition (M=2)
         ENTRY DB3SLV(W,N,B, X)      ! solution B -> X
         ENTRY DB3IEL(W,N, V)        ! V = inverse band matrix elements

Definition in file Dbandmatrix.f90.

Function/Subroutine Documentation

◆ condes()

real(mps) function condes ( real(mpd), dimension(*), intent(in)  w,
integer(mpi), intent(in)  n,
real(mpd), dimension(n), intent(inout)  aux 
)

Etimate condition.

Parameters
[in]Wsymmetric matrix
[in]Nsize
[in]AUXscratch array
Returns
condition

Definition at line 345 of file Dbandmatrix.f90.

346 USE mpdef
347
348 implicit none
349 REAL(mps) :: cond
350 INTEGER(mpi) :: i
351 INTEGER(mpi) :: ir
352 INTEGER(mpi) :: is
353 INTEGER(mpi) :: k
354 INTEGER(mpi) :: kk
355 REAL(mps) :: xla1
356 REAL(mps) :: xlan
357
358
359 REAL(mpd), INTENT(IN) :: w(*)
360 INTEGER(mpi), INTENT(IN) :: n
361 REAL(mpd), INTENT(IN OUT) :: aux(n)
362
363 REAL(mpd) :: suma,sumu,sums
364
365 ir=1
366 is=1
367 DO i=1,n
368 IF(w((i*i+i)/2) < w((is*is+is)/2)) is=i ! largest Dii
369 IF(w((i*i+i)/2) > w((ir*ir+ir)/2)) ir=i ! smallest Dii
370 END DO
371
372 sumu=0.0 ! find smallest eigenvalue
373 sums=0.0
374 DO i=n,1,-1 ! backward
375 suma=0.0
376 IF(i == ir) suma=1.0_mpd
377 kk=(i*i+i)/2
378 DO k=i+1,n
379 suma=suma-w(kk+i)*aux(k) ! (K,I)
380 kk=kk+k
381 END DO
382 aux(i)=suma
383 sumu=sumu+aux(i)*aux(i)
384 END DO
385 xlan=real(w((ir*ir+ir)/2)*sqrt(sumu),mps)
386 IF(xlan /= 0.0) xlan=1.0/xlan
387
388 DO i=1,n
389 IF(i == is) THEN
390 sums=1.0_mpd
391 ELSE IF(i > is) THEN
392 sums=sums+w(is+(i*i-i)/2)**2
393 END IF
394 END DO ! is Ws
395 xla1=0.0
396 IF(w((is*is+is)/2) /= 0.0) xla1=real(sqrt(sums)/w((is*is+is)/2),mps)
397
398 cond=0.0
399 IF(xla1 > 0.0.AND.xlan > 0.0) cond=xla1/xlan
400 ! estimated condition
401 condes=cond
real(mps) function condes(w, n, aux)
Etimate condition.
Definition of constants.
Definition mpdef.f90:24
integer, parameter mps
Definition mpdef.f90:37

◆ db2dec()

subroutine db2dec ( real(mpd), dimension(2,n), intent(inout)  w,
integer(mpi), intent(inout)  n,
real(mpd), dimension(n), intent(out)  aux 
)

Decomposition (M=1).

W is a symmetrix positive definite band matrix of bandwidth 1(+1). W(1,.) are the diagonal elements, W(2,.) is the next diagonals; W(2,N) is never referenced. AUX is an auxiliary array of length N. W is decomposed to L D Lt, where D = diagonal and L unit triangular. A row is set to zero, if the diagonal element is reduced in previous steps by a word length (i.e. global correlation coefficient large). The resulting L and D replace W: the diagonal elements W(1,...) will contain the inverse of the D-elements; the diagonal elements of L are all 1 and not stored. The other elements of L are stored in the corresponding elements of W.

ENTRY DB2SLV(W,N,B, X), solution B -> X
ENTRY DB2IEL(W,N, V), V = inverse band matrix elements

Parameters
[in,out]Wsymmetric band matrix
[in]Nsize
[in]AUXscratch array

Definition at line 622 of file Dbandmatrix.f90.

623 USE mpdef
624
625 implicit none
626 INTEGER(mpi) :: i
627
628
629 REAL(mpd), INTENT(IN OUT) :: w(2,n)
630 INTEGER(mpi), INTENT(IN OUT) :: n
631 REAL(mpd), INTENT(OUT) :: aux(n)
632
633 REAL(mpd) :: v(2,n),b(n),x(n), rxw
634
635 DO i=1,n
636 aux(i)=16.0_mpd*w(1,i) ! save diagonal elements
637 END DO
638 DO i=1,n-1
639 IF(w(1,i)+aux(i) /= aux(i)) THEN
640 w(1,i)=1.0_mpd/w(1,i)
641 rxw=w(2,i)*w(1,i)
642 w(1,i+1)=w(1,i+1)-w(2,i)*rxw
643 w(2,i)=rxw
644 ELSE ! singular
645 w(1,i)=0.0_mpd
646 w(2,i)=0.0_mpd
647 END IF
648 END DO
649 IF(w(1,n)+aux(n) > aux(n)) THEN ! N
650 w(1,n)=1.0_mpd/w(1,n)
651 ELSE ! singular
652 w(1,n)=0.0_mpd
653 END IF
654 RETURN
655
656 entry db2slv(w,n,b, x) ! solution B -> X
657 ! The equation W(original)*X=B is solved for X; input is B in vector X.
658 DO i=1,n
659 x(i)=b(i)
660 END DO
661 DO i=1,n-1 ! by forward substitution
662 x(i+1)=x(i+1)-w(2,i)*x(i)
663 END DO
664 x(n)=x(n)*w(1,n) ! and backward substitution
665 DO i=n-1,1,-1
666 x(i)=x(i)*w(1,i)-w(2,i)*x(i+1)
667 END DO
668 RETURN
669
670 entry db2iel(w,n, v) ! V = inverse band matrix elements
671 ! The band elements of the inverse of W(original) are calculated,
672 ! and stored in V in the same order as in W.
673 ! Remaining elements of the inverse are not calculated.
674 v(1,n )= w(1,n)
675 v(2,n-1)=-v(1,n )*w(2,n-1)
676 DO i=n-1,3,-1
677 v(1,i )= w(1,i )-v(2,i )*w(2,i )
678 v(2,i-1)=-v(1,i )*w(2,i-1)
679 END DO
680 v(1,2)= w(1,2)-v(2,2)*w(2,2)
681 v(2,1)=-v(1,2)*w(2,1)
682 v(1,1)= w(1,1)-v(2,1)*w(2,1)

◆ db3dec()

subroutine db3dec ( real(mpd), dimension(3,n), intent(inout)  w,
integer(mpi), intent(inout)  n,
real(mpd), dimension(n), intent(out)  aux 
)

Decomposition (M=2).

W is a symmetrix positive definite band matrix of bandwidth 2(+1). W(1,.) are the diagonal elements, W(2,.) and W(3,.) are the next diagonals; W(3,N-1), W(2,N) and W(3,N) are never referenced. AUX is an auxiliary array of length N. W is decomposed to L D Lt, where D = diagonal and L unit triangular. A row is set to zero, if the diagonal element is reduced in previous steps by a word length (i.e. global correlation coefficient large). The resulting L and D replace W: the diagonal elements W(1,...) will contain the inverse of the D-elements; the diagonal elements of L are all 1 and not stored. The other elements of L are stored in the corresponding elements of W.

ENTRY DB3SLV(W,N,B, X), solution B -> X
ENTRY DB3IEL(W,N, V), V = inverse band matrix elements

Parameters
[in,out]Wsymmetric band matrix
[in]Nsize
[in]AUXscratch array

Definition at line 710 of file Dbandmatrix.f90.

711 USE mpdef
712
713 implicit none
714 INTEGER(mpi) :: i
715
716
717 REAL(mpd), INTENT(IN OUT) :: w(3,n)
718 INTEGER(mpi), INTENT(IN OUT) :: n
719 REAL(mpd), INTENT(OUT) :: aux(n)
720 ! decompos
721
722 REAL(mpd) :: v(3,n),b(n),x(n), rxw
723
724 DO i=1,n
725 aux(i)=16.0_mpd*w(1,i) ! save diagonal elements
726 END DO
727 DO i=1,n-2
728 IF(w(1,i)+aux(i) /= aux(i)) THEN
729 w(1,i)=1.0_mpd/w(1,i)
730 rxw=w(2,i)*w(1,i)
731 w(1,i+1)=w(1,i+1)-w(2,i)*rxw
732 w(2,i+1)=w(2,i+1)-w(3,i)*rxw
733 w(2,i)=rxw
734 rxw=w(3,i)*w(1,i)
735 w(1,i+2)=w(1,i+2)-w(3,i)*rxw
736 w(3,i)=rxw
737 ELSE ! singular
738 w(1,i)=0.0_mpd
739 w(2,i)=0.0_mpd
740 w(3,i)=0.0_mpd
741 END IF
742 END DO
743 IF(w(1,n-1)+aux(n-1) > aux(n-1)) THEN
744 w(1,n-1)=1.0_mpd/w(1,n-1)
745 rxw=w(2,n-1)*w(1,n-1)
746 w(1,n)=w(1,n)-w(2,n-1)*rxw
747 w(2,n-1)=rxw
748 ELSE ! singular
749 w(1,n-1)=0.0_mpd
750 w(2,n-1)=0.0_mpd
751 END IF
752 IF(w(1,n)+aux(n) > aux(n)) THEN
753 w(1,n)=1.0_mpd/w(1,n)
754 ELSE ! singular
755 w(1,n)=0.0_mpd
756 END IF
757 RETURN
758
759 entry db3slv(w,n,b, x) ! solution B -> X
760 DO i=1,n
761 x(i)=b(i)
762 END DO
763 DO i=1,n-2 ! by forward substitution
764 x(i+1)=x(i+1)-w(2,i)*x(i)
765 x(i+2)=x(i+2)-w(3,i)*x(i)
766 END DO
767 x(n)=x(n)-w(2,n-1)*x(n-1)
768 x(n)=x(n)*w(1,n) ! and backward substitution
769 x(n-1)=x(n-1)*w(1,n-1)-w(2,n-1)*x(n)
770 DO i=n-2,1,-1
771 x(i)=x(i)*w(1,i)-w(2,i)*x(i+1)-w(3,i)*x(i+2)
772 END DO
773 RETURN
774
775 entry db3iel(w,n, v) ! V = inverse band matrix elements
776 ! The band elements of the inverse of W(original) are calculated,
777 ! and stored in V in the same order as in W.
778 ! Remaining elements of the inverse are not calculated.
779 v(1,n )= w(1,n)
780 v(2,n-1)=-v(1,n )*w(2,n-1)
781 v(3,n-2)=-v(2,n-1)*w(2,n-2)-v(1,n )*w(3,n-2)
782 v(1,n-1)= w(1,n-1) -v(2,n-1)*w(2,n-1)
783 v(2,n-2)=-v(1,n-1)*w(2,n-2)-v(2,n-1)*w(3,n-2)
784 v(3,n-3)=-v(2,n-2)*w(2,n-3)-v(1,n-1)*w(3,n-3)
785 DO i=n-2,3,-1
786 v(1,i )= w(1,i ) -v(2,i )*w(2,i )-v(3,i)*w(3,i )
787 v(2,i-1)=-v(1,i )*w(2,i-1)-v(2,i)*w(3,i-1)
788 v(3,i-2)=-v(2,i-1)*w(2,i-2)-v(1,i)*w(3,i-2)
789 END DO
790 v(1,2)= w(1,2) -v(2,2)*w(2,2)-v(3,2)*w(3,2)
791 v(2,1)=-v(1,2)*w(2,1)-v(2,2)*w(3,1)
792 v(1,1)= w(1,1) -v(2,1)*w(2,1)-v(3,1)*w(3,1)

◆ dbcdec()

subroutine dbcdec ( real(mpd), dimension(mp1,n), intent(inout)  w,
integer(mpi), intent(in)  mp1,
integer(mpi), intent(in)  n,
real(mpd), dimension(n), intent(out)  aux 
)

Decomposition of symmetric band matrix.

ENTRY DBCSLV(W,MP1,N,B, X) for solution B -> X
ENTRY DBCIEL(W,MP1,N, V), V = inverse band matrix elements
ENTRY DBCINB(W,MP1,N, VS), VS = band part of inverse symmetric matrix
ENTRY DBCINV(W,MP1,N, VS), V = inverse symmetric matrix

Parameters
[in,out]Wsymmetric band matrix
[in]MP1band width (M) + 1
[in]Nsize
[in]AUXscratch array

Definition at line 419 of file Dbandmatrix.f90.

420 USE mpdef
421
422 implicit none
423 INTEGER(mpi) :: i
424 INTEGER(mpi) :: j
425 INTEGER(mpi) :: k
426 ! M=MP1-1 N*M(M-1) dot operations
427
428 REAL(mpd), INTENT(IN OUT) :: w(mp1,n)
429 INTEGER(mpi), INTENT(IN) :: mp1
430 INTEGER(mpi), INTENT(IN) :: n
431 REAL(mpd), INTENT(OUT) :: aux(n)
432 ! decompos
433 REAL(mpd) :: v(mp1,n),b(n),x(n), vs(*),rxw
434 ! ...
435 DO i=1,n
436 aux(i)=16.0_mpd*w(1,i) ! save diagonal elements
437 END DO
438 DO i=1,n
439 IF(w(1,i)+aux(i) /= aux(i)) THEN
440 w(1,i)=1.0/w(1,i)
441 ELSE
442 w(1,i)=0.0_mpd ! singular
443 END IF
444 DO j=1,min(mp1-1,n-i)
445 rxw=w(j+1,i)*w(1,i)
446 DO k=1,min(mp1-1,n-i)+1-j
447 w(k,i+j)=w(k,i+j)-w(k+j,i)*rxw
448 END DO
449 w(j+1,i)=rxw
450 END DO
451 END DO
452 RETURN
453
454 entry dbcslv(w,mp1,n,b, x) ! solution B -> X
455 ! N*(2M-1) dot operations
456 DO i=1,n
457 x(i)=b(i)
458 END DO
459 DO i=1,n ! forward substitution
460 DO j=1,min(mp1-1,n-i)
461 x(j+i)=x(j+i)-w(j+1,i)*x(i)
462 END DO
463 END DO
464 DO i=n,1,-1 ! backward substitution
465 rxw=x(i)*w(1,i)
466 DO j=1,min(mp1-1,n-i)
467 rxw=rxw-w(j+1,i)*x(j+i)
468 END DO
469 x(i)=rxw
470 END DO
471 RETURN
472
473 entry dbciel(w,mp1,n, v) ! V = inverse band matrix elements
474 ! N*M*(M-1) dot operations
475 DO i=n,1,-1
476 rxw=w(1,i)
477 DO j=i,max(1,i-mp1+1),-1
478 DO k=j+1,min(n,j+mp1-1)
479 rxw=rxw-v(1+abs(i-k),min(i,k))*w(1+k-j,j)
480 END DO
481 v(1+i-j,j)=rxw
482 rxw=0.0
483 END DO
484 END DO
485 RETURN
486
487 entry dbcinb(w,mp1,n, vs) ! VS = band part of inverse symmetric matrix
488 ! N*M*(M-1) dot operations
489 DO i=n,1,-1
490 rxw=w(1,i)
491 DO j=i,max(1,i-mp1+1),-1
492 DO k=j+1,min(n,j+mp1-1)
493 rxw=rxw-vs((max(i,k)*(max(i,k)-1))/2+min(i,k))*w(1+k-j,j)
494 END DO
495 vs((i*i-i)/2+j)=rxw
496 rxw=0.0
497 END DO
498 ! DO J=MAX(1,I-MP1+1)-1,1,-1
499 ! VS((I*I-I)/2+J)=0.0
500 ! END DO
501 END DO
502 RETURN
503
504 entry dbcinv(w,mp1,n, vs) ! V = inverse symmetric matrix
505 ! N*N/2*(M-1) dot operations
506 DO i=n,1,-1
507 rxw=w(1,i)
508 DO j=i,1,-1
509 DO k=j+1,min(n,j+mp1-1)
510 rxw=rxw-vs((max(i,k)*(max(i,k)-1))/2+min(i,k))*w(1+k-j,j)
511 END DO
512 vs((i*i-i)/2+j)=rxw
513 rxw=0.0
514 END DO
515 END DO
516 RETURN

◆ dbcprb()

subroutine dbcprb ( real(mpd), dimension(mp1,n), intent(inout)  w,
integer(mpi), intent(in)  mp1,
integer(mpi), intent(in)  n 
)

Print band matrix.

Parameters
[in]Wsymmetric band matrix
[in]MP1band width (M) + 1
[in]Nsize

Definition at line 572 of file Dbandmatrix.f90.

573 USE mpdef
574
575 implicit none
576 INTEGER(mpi) :: i
577 INTEGER(mpi) :: j
578
579
580 REAL(mpd), INTENT(IN OUT) :: w(mp1,n)
581 INTEGER(mpi), INTENT(IN) :: mp1
582 INTEGER(mpi), INTENT(IN) :: n
583
584
585 ! ...
586 IF(mp1 > 6) RETURN
587 WRITE(*,*) ' '
588 WRITE(*,101)
589 DO i=1,n
590 WRITE(*,102) i,(w(j,i),j=1,mp1)
591 END DO
592 WRITE(*,*) ' '
593101 FORMAT(5x,'i Diag ')
594102 FORMAT(1x,i5,6g12.4)

◆ dbcprv()

subroutine dbcprv ( real(mpd), dimension(mp1,n), intent(inout)  w,
integer(mpi), intent(in)  mp1,
integer(mpi), intent(in)  n,
real(mpd), dimension(n), intent(out)  b 
)

Print corr band matrix and pars.

Parameters
[in]Wsymmetric band matrix
[in]MP1band width (M) + 1
[in]Nsize
[in]Bvector

Definition at line 526 of file Dbandmatrix.f90.

527 USE mpdef
528
529 implicit none
530 INTEGER(mpi) :: i
531 INTEGER(mpi) :: j
532 INTEGER(mpi) :: nj
533 REAL(mps) :: rho
534
535
536 REAL(mpd), INTENT(IN OUT) :: w(mp1,n)
537 INTEGER(mpi), INTENT(IN) :: mp1
538 INTEGER(mpi), INTENT(IN) :: n
539 REAL(mpd), INTENT(OUT) :: b(n)
540
541 REAL(mpd) :: ERR
542 INTEGER(mpi) :: irho(5)
543 ! ...
544 WRITE(*,*) ' '
545 WRITE(*,101)
546
547 DO i=1,n
548 err=sqrt(w(1,i))
549 nj=0
550 DO j=2,mp1
551 IF(i+1-j > 0.AND.nj < 5) THEN
552 nj=nj+1
553 rho=real(w(j,i+1-j)/(err*sqrt(w(1,i+1-j))),mps)
554 irho(nj)=nint(100.0*abs(rho),mpi)
555 IF(rho < 0.0) irho(nj)=-irho(nj)
556 END IF
557 END DO
558 WRITE(*,102) i,b(i),err,(irho(j),j=1,nj)
559 END DO
560 WRITE(*,103)
561101 FORMAT(5x,'i Param',7x,'error',7x,' c(i,i-1) c(i,i-2)'/)
562102 FORMAT(1x,i5,2g12.4,1x,5i9)
563103 FORMAT(33x,'(correlation coefficients in percent)')
integer, parameter mpi
Definition mpdef.f90:34

◆ dbfdec()

subroutine dbfdec ( real(mpd), dimension(mp1,n), intent(out)  w,
integer(mpi), intent(inout)  mp1,
integer(mpi), intent(in)  n 
)

Decomposition of symmetric band matrix.

Band matrix modified Cholesky decomposition, Philip E.Gill, Walter Murray and Margarete H.Wright: Practical Optimization, Academic Press, 1981

Parameters
[in,out]Wsymmetric band matrix
[in]MP1band width (M) + 1
[in]Nsize

Definition at line 904 of file Dbandmatrix.f90.

905 USE mpdef
906
907 IMPLICIT NONE
908 REAL(mpd), INTENT(OUT) :: w(mp1,n)
909 INTEGER(mpi), INTENT(IN OUT) :: mp1
910 INTEGER(mpi), INTENT(IN) :: n
911 INTEGER(mpi) :: i,j,k
912 REAL(mpd) :: epsm,gamm,xchi,beta,delta,theta
913
914 epsm=epsilon(epsm) ! machine precision
915 gamm=0.0_mpd ! max diagonal element
916 xchi=0.0_mpd ! max off-diagonal element
917 DO k=1,n
918 gamm=max(gamm,abs(w(1,k)))
919 DO j=2,min(mp1,n-k+1)
920 xchi=max(xchi,abs(w(j,k)))
921 END DO
922 END DO
923 beta=sqrt(max(gamm,xchi/max(1.0_mpd,sqrt(real(n*n-1,mpd))),epsm))
924 delta=epsm*max(1.0_mpd,gamm+xchi)
925
926 DO k=1,n
927 DO i=2,min(mp1,k)
928 w(i,k-i+1)=w(i,k-i+1)*w(1,k-i+1)
929 END DO
930 DO j=2,min(mp1,n-k+1)
931 DO i=max(2,j+k+1-mp1),k
932 w(j,k)=w(j,k)-w(k-i+2,i-1)*w(j-i+k+1,i-1)
933 END DO
934 END DO
935 theta=0.0_mpd
936 DO j=2,min(mp1,n-k+1)
937 theta=max(theta,abs(w(j,k)))
938 END DO
939 w(1,k)=1.0_mpd/max(abs(w(1,k)),(theta/beta)**2,delta)
940 DO j=2,min(mp1,n-k+1)
941 w(1,k+j-1)=w(1,k+j-1)-w(1,k)*w(j,k)**2
942 END DO
943 END DO ! K
944
integer, parameter mpd
Definition mpdef.f90:38

◆ dcfdec()

subroutine dcfdec ( real(mpd), dimension(*), intent(out)  w,
integer(mpi), intent(in)  n 
)

Decomposition of symmetric matrix.

Modified Cholesky decomposition, Philip E.Gill, Walter Murray and Margarete H.Wright: Practical Optimization, Academic Press, 1981

Parameters
[in,out]Wsymmetirc matrix
[in]Nsize

Definition at line 852 of file Dbandmatrix.f90.

853 USE mpdef
854
855 IMPLICIT NONE
856 REAL(mpd), INTENT(OUT) :: w(*)
857 INTEGER(mpi), INTENT(IN) :: n
858 INTEGER(mpi) :: i,j,k
859 REAL(mpd) :: epsm,gamm,xchi,beta,delta,theta
860
861 epsm=epsilon(epsm) ! machine precision
862 gamm=0.0_mpd ! max diagonal element
863 xchi=0.0_mpd ! max off-diagonal element
864 DO k=1,n
865 gamm=max(gamm,abs(w((k*k+k)/2)))
866 DO j=k+1,n
867 xchi=max(xchi,abs(w((j*j-j)/2+k)))
868 END DO
869 END DO
870 beta=sqrt(max(gamm,xchi/max(1.0_mpd,sqrt(real(n*n-1,mpd))),epsm))
871 delta=epsm*max(1.0_mpd,gamm+xchi)
872
873 DO k=1,n
874 DO i=1,k-1
875 w((k*k-k)/2+i)=w((k*k-k)/2+i)*w((i*i+i)/2)
876 END DO
877 DO j=k+1,n
878 DO i=1,k-1
879 w((j*j-j)/2+k)=w((j*j-j)/2+k)-w((k*k-k)/2+i)*w((j*j-j)/2+i)
880 END DO
881 END DO
882 theta=0.0_mpd
883 DO j=k+1,n
884 theta=max(theta,abs(w((j*j-j)/2+k)))
885 END DO
886 w((k*k+k)/2)=1.0_mpd/max(abs(w((k*k+k)/2)),(theta/beta)**2,delta)
887 DO j=k+1,n
888 w((j*j+j)/2)=w((j*j+j)/2)-w((j*j-j)/2+k)**2*w((k*k+k)/2)
889 END DO
890 END DO ! K
891

◆ dchdec()

subroutine dchdec ( real(mpd), dimension(*), intent(inout)  w,
integer(mpi), intent(in)  n,
real(mpd), dimension(n), intent(out)  aux 
)

Decomposition of symmetric matrix.

ENTRY DCHSLV(W,N,B, X) for solution B -> X
ENTRY DCHINV(W,N,V) for inversion

Parameters
[in,out]Wsymmetirc matrix
[in]Nsize
[in]AUXscratch array

Definition at line 245 of file Dbandmatrix.f90.

246 USE mpdef
247
248 implicit none
249 INTEGER(mpi) :: i
250 INTEGER(mpi) :: ii
251 INTEGER(mpi) :: j
252 INTEGER(mpi) :: jj
253 INTEGER(mpi) :: k
254 INTEGER(mpi) :: kk
255 INTEGER(mpi) :: l
256 INTEGER(mpi) :: m
257
258
259 REAL(mpd), INTENT(IN OUT) :: w(*)
260 INTEGER(mpi), INTENT(IN) :: n
261 REAL(mpd), INTENT(OUT) :: aux(n)
262
263 REAL(mpd) :: b(*),x(*),v(*),suma,ratio
264 ! ...
265 DO i=1,n
266 aux(i)=16.0_mpd*w((i*i+i)/2) ! save diagonal elements
267 END DO
268 ii=0
269 DO i=1,n
270 ii=ii+i
271 IF(w(ii)+aux(i) /= aux(i)) THEN ! GT
272 w(ii)=1.0_mpd/w(ii) ! (I,I) div !
273 ELSE
274 w(ii)=0.0_mpd
275 END IF
276 jj=ii
277 DO j=i+1,n
278 ratio=w(i+jj)*w(ii) ! (I,J) (I,I)
279 kk=jj
280 DO k=j,n
281 w(kk+j)=w(kk+j)-w(kk+i)*ratio ! (K,J) (K,I)
282 kk=kk+k
283 END DO ! K
284 w(i+jj)=ratio ! (I,J)
285 jj=jj+j
286 END DO ! J
287 END DO ! I
288
289
290 RETURN
291
292 entry dchslv(w,n,b, x) ! solution B -> X
293 WRITE(*,*) 'before copy'
294 DO i=1,n
295 x(i)=b(i)
296 END DO
297 WRITE(*,*) 'after copy'
298 ii=0
299 DO i=1,n
300 suma=x(i)
301 DO k=1,i-1
302 suma=suma-w(k+ii)*x(k) ! (K,I)
303 END DO
304 x(i)=suma
305 ii=ii+i
306 END DO
307 WRITE(*,*) 'after forward'
308 DO i=n,1,-1
309 suma=x(i)*w(ii) ! (I,I)
310 kk=ii
311 DO k=i+1,n
312 suma=suma-w(kk+i)*x(k) ! (K,I)
313 kk=kk+k
314 END DO
315 x(i)=suma
316 ii=ii-i
317 END DO
318 WRITE(*,*) 'after backward'
319 RETURN
320
321 entry dchinv(w,n,v) ! inversion
322 ii=(n*n-n)/2
323 DO i=n,1,-1
324 suma=w(ii+i) ! (I,I)
325 DO j=i,1,-1
326 DO k=j+1,n
327 l=min(i,k)
328 m=max(i,k)
329 suma=suma-w(j+(k*k-k)/2)*v(l+(m*m-m)/2) ! (J,K) (I,K)
330 END DO
331 v(ii+j)=suma ! (I,J)
332 suma=0.0_mpd
333 END DO
334 ii=ii-i+1
335 END DO