\documentstyle [11pt] {article}
\pagestyle{empty}
%
\topmargin=-0.75in
\hoffset=-0.75in
\textheight=10.0in \vsize\textheight
\textwidth=6.5in \hsize\textwidth
%
\begin {document}
{\Large
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Insert source immediately following \begin{verbatim}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\normalsize
\begin{verbatim}
      SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )
*
*  -- LAPACK driver routine (version 2.0) --
*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
*     Courant Institute, Argonne National Lab, and Rice University
*     March 31, 1993
*
*     .. Scalar Arguments ..
      INTEGER            INFO, LDA, LDB, N, NRHS
*     ..
*     .. Array Arguments ..
      INTEGER            IPIV( * )
      DOUBLE PRECISION   A( LDA, * ), B( LDB, * )
\end{verbatim}
\clearpage
\begin{verbatim}
*
*  Purpose
*  =======
*
*  DGESV computes the solution to a real system of linear equations
*     A * X = B,
*  where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
*
*  The LU decomposition with partial pivoting and row interchanges is
*  used to factor A as
*     A = P * L * U,
*  where P is a permutation matrix, L is unit lower triangular, and U is
*  upper triangular.  The factored form of A is then used to solve the
*  system of equations A * X = B.
*
*  Arguments
*  =========
*
*  N       (input) INTEGER
*          The number of linear equations, i.e., the order of the
*          matrix A.  N >= 0.
*
*  NRHS    (input) INTEGER
*          The number of right hand sides, i.e., the number of columns
*          of the matrix B.  NRHS >= 0.
*
*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
*          On entry, the N-by-N coefficient matrix A.
*          On exit, the factors L and U from the factorization
*          A = P*L*U; the unit diagonal elements of L are not stored.
*
*  LDA     (input) INTEGER
*          The leading dimension of the array A.  LDA >= max(1,N).
*
*  IPIV    (output) INTEGER array, dimension (N)
*          The pivot indices that define the permutation matrix P;
*          row i of the matrix was interchanged with row IPIV(i).
*
*  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
*          On entry, the N-by-NRHS matrix of right hand side matrix B.
*          On exit, if INFO = 0, the N-by-NRHS solution matrix X.
*
*  LDB     (input) INTEGER
*          The leading dimension of the array B.  LDB >= max(1,N).
*
*  INFO    (output) INTEGER
*          = 0:  successful exit
*          < 0:  if INFO = -i, the i-th argument had an illegal value
*          > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
*                has been completed, but the factor U is exactly
*                singular, so the solution could not be computed.
*
*  =====================================================================
\end{verbatim}
}
\clearpage
\begin{verbatim}
c-----------------------------------------------------------
c     Test program for LAPACK "driver" routine 'dgesv' 
c     which computes the solution of a real system
c     of linear equations:  A x = b
c
c     Version 1: Uses fixed-size 2-d arrays.
c-----------------------------------------------------------
      program         tdgesv1

      implicit        none
c-----------------------------------------------------------
c     Maximum size of linear system.
c-----------------------------------------------------------
      integer         maxn
      parameter     ( maxn = 100 )

c-----------------------------------------------------------
c     Storage for arrays 
c-----------------------------------------------------------
      real*8          a(maxn,maxn),   asave(maxn,maxn),
     &                b(maxn),        x(maxn)
      integer         ipiv(maxn)
      integer         d1a,            d2a       

      integer         i,              nrhs,      
     &                n,              info
\end{verbatim}
\clearpage
\begin{verbatim}
c-----------------------------------------------------------
c     Set up sample 3 x 3 system ...
c-----------------------------------------------------------
      a(1,1) =  1.23d0
      a(1,2) =  0.24d0
      a(1,3) = -0.45d0

      a(2,1) = -0.43d0
      a(2,2) =  2.45d0
      a(2,3) =  0.78d0

      a(3,1) =  0.51d0
      a(3,2) = -0.68d0
      a(3,3) =  3.23d0

      b(1)   =  6.78d0
      b(2)   = -3.45d0
      b(3)   =  1.67d0

c-----------------------------------------------------------
c     ... and solve it.  Note that 'dgsev' is general 
c     enough to solve A x_i = b_i for multiple right-hand-
c     sides b_i.  Here we have only one right-hand-side.
c     Also note that the procedure performs the LU 
c     decomposition in place, thus destroying the 
c     input-matrix, it also overwrites the right-hand-side(s)
c     with the solution(s).  Finally, observe that we 
c     pass the "leading dimension" (maxn) of both 'a' and 
c     'b' to the routine.  This allows us to load array
c     elements in the main program as we have just done,
c     without running into troubles due to the fact that 
c     these elements ARE NOT all contiguous in memory.
c-----------------------------------------------------------
      n    = 3
      nrhs = 1

      call dgesv( n, nrhs, a, maxn, ipiv, b, maxn, info )
\end{verbatim}
\clearpage
\begin{verbatim}
      if(      info .eq. 0 ) then
c-----------------------------------------------------------
c        Solution successful, write soln to stdout.       
c        Note the use of "implied-do-loop" to write a 
c        sequence of elements: the enclosing parenthesis 
c        around the  "loop" are required.
c-----------------------------------------------------------
         write(*,*) ( b(i) , i = 1 , n )
      else if( info .lt. 0 ) then
c-----------------------------------------------------------
c        Bad argument detected.
c-----------------------------------------------------------
         write(0,*) 'tdgesv1: Argument ', abs(info), 
     &              ' to dgesv() is invalid'
      else 
c-----------------------------------------------------------
c        Matrix is singular.
c-----------------------------------------------------------
         write(0,*) 'tdgesv1: dgesv() detected singular ',
     &              'matrix'
      end if
      

      stop

      end
\end{verbatim}
\clearpage
\begin{verbatim}
#############################################################
# Building 'tdgesv' and sample output on the SGIs
#############################################################

einstein% pwd; ls
Makefile    tdgesv1.f

einstein% printenv LIBBLAS
-lblas

einstein% more Makefile
############################################################
#  Note that this 'Makefile' assumes that the following
#  environment variables are set:
#
#     F77
#     F77FLAGS
#     F77CFLAGS
#     F77LFLAGS
#     LIBBLAS  
#
#  Put the appropriate 'setenv' commands in your '~/.cshrc'.  
#  See 'phy329@einstein:~/.cshrc' for an example.
############################################################
.IGNORE:

F77_COMPILE  = $(F77) $(F77FLAGS) $(F77CFLAGS)
F77_LOAD     = $(F77) $(F77FLAGS) $(F77LFLAGS)

.f.o:
        $(F77_COMPILE) $*.f

EXECUTABLES = tdgesv1

all: $(EXECUTABLES)

tdgesv1: tdgesv1.o 
        $(F77_LOAD) tdgesv1.o -lp329f -llapack $(LIBBLAS) \
                    -o tdgesv1

einstein% make
   f77 -g -c tdgesv1.f
   f77 -g -L/usr/local/lib tdgesv1.o -lp329f -llapack -lblas \
       -o tdgesv1

einstein% tdgesv1

    5.426364412431639     -0.3257753768173935     -0.4083508069894624    

\end{verbatim}
\clearpage
\begin{verbatim}
#############################################################
# Building 'tdgesv' and sample output on the Crays
#############################################################

#############################################################
# First 'rcp' source from SGIs to Cray
#############################################################

einstein% pwd; ls
/usr2/people/phy329/linsys/ex1
Makefile    tdgesv1.f

einstein% rcp * phas761@charon:~/phy329/linsys/ex1

#############################################################
# Now login to the Cray and translate the source.  Note 
# that the script handles the change in name of the 
# real*8 LAPACK routine from 'dgesv' to 'sgesv'.
#############################################################

einstein% rlogin phas761@charon

charon% cd phy329/linsys/ex1; ls
Makefile    tdgesv1.f

charon% f77transcray tdgesv1.f
f77transcray: Translating tdgesv1.f

charon% cat tdgesv1.f
c-----------------------------------------------------------
c     Test program for LAPACK "driver" routine 'dgesv' 
c     which computes the solution of a real system
c     of linear equations:  A x = b
c
c     Version 1: Uses fixed-size 2-d arrays.
c-----------------------------------------------------------
      program         tdgesv1

      implicit        none
\end{verbatim}
\clearpage
\begin{verbatim}
c-----------------------------------------------------------
c     Maximum size of linear system.
c-----------------------------------------------------------
      integer         maxn
      parameter     ( maxn = 100 )

c-----------------------------------------------------------
c     Storage for arrays 
c-----------------------------------------------------------
      real            a(maxn,maxn),   asave(maxn,maxn),
     &                b(maxn),        x(maxn)
      integer         ipiv(maxn)
      integer         d1a,            d2a       

      integer         i,              nrhs,      
     &                n,              info

c-----------------------------------------------------------
c     Set up sample 3 x 3 system ...
c-----------------------------------------------------------
      a(1,1) =  1.23e0
      a(1,2) =  0.24e0
      a(1,3) = -0.45e0

      a(2,1) = -0.43e0
      a(2,2) =  2.45e0
      a(2,3) =  0.78e0

      a(3,1) =  0.51e0
      a(3,2) = -0.68e0
      a(3,3) =  3.23e0

      b(1)   =  6.78e0
      b(2)   = -3.45e0
      b(3)   =  1.67e0
\end{verbatim}
\clearpage
\begin{verbatim}
c-----------------------------------------------------------
c     ... and solve it.  Note that 'dgsev' is general 
c     enough to solve A x_i = b_i for multiple right-hand-
c     sides b_i.  Here we have only one right-hand-side.
c     Also note that the procedure performs the LU 
c     decomposition in place, thus destroying the 
c     input-matrix, it also overwrites the right-hand-side(s)
c     with the solution(s).  Finally, observe that we 
c     pass the "leading dimension" (maxn) of both 'a' and 
c     'b' to the routine.  This allows us to load array
c     elements in the main program as we have just done,
c     without running into troubles due to the fact that 
c     these elements ARE NOT all contiguous in memory.
c-----------------------------------------------------------
      n    = 3
      nrhs = 1

      call sgesv( n, nrhs, a, maxn, ipiv, b, maxn, info )

                              .
                              .
                              .
\end{verbatim}
\clearpage
\begin{verbatim}
#############################################################
# The 'blas' library is built-in on the Cray, so we do not 
# have to specify '-lblas' during the load phase.  The 
# Makefile works properly provided LIBBLAS is either 
# unset, or set to nothing (see ~/.cshrc on this account).
#############################################################

charon% make
        cf77 -g -c tdgesv1.f
        cf77 -g -L/hpcf/u0/ph/as/phas761/lib tdgesv1.o \
             -lp329f -llapack  -o tdgesv1

charon% tdgsev1


 5.426364412431667,  -0.325775376817397,  -0.4083508069894641

 STOP executed at line 89 in Fortran routine 'TDGESV1'
 CPU: 0.005s,  Wallclock: 0.024s,  4.5% of 5-CPU Machine
 Memory HWM: 212775, Stack HWM: 16509, Stack segment expansions: 0
\end{verbatim}
}
%
\end {document}
