
IMSL at UM/MCSR
Visual Numerics’ International Mathematical Statistical Library, or IMSL,
contains a set of mathematical, statistical, and other routines. A routine or
a subroutine is a program that performs certain function. For example a
subroutine may be written to obtain a “sin” or “cos” of an angle. When many of
these routines are written and put together sometimes they are call “library”.
Many universities, companies, as well as state and federal government
agencies, use IMSL every day to solve their very complex problems. Fortran or
C developers and researchers at these institutions can call one or more
routines from IMSL to solve a system of equations, rather than having to
write those complex routines themselves
For example, if we have a set of three equations and three unknowns and
wanted to solve these equations, we write a simple Fortran program that
contains our datathe coefficient for the three equations together with
what these equations are equal to (the right hand side of these equations).
Our Fortran program then calls one or more routines from the IMSL library to
solve our original equations. The alternative is for us to write the Fortran
and or C routines ourselves to solve the equations, but this would take a
lot of time and effort. So, IMSL for example has a routine that is called
LSLRG. This routine is for solving a very, very simple set of linear
equations. A programmer passes the coefficients of their simple equations to
IMSL. IMSL then solves these equations and passes the answers to the user.
This prevents “inventing the wheel” over and over again and saves a lot of
time. Ordinary userwritten routines can not be as efficient or fastrunning
as IMSL routines, unless we are inventing a new method to solve a linear or
nonlinear equations, and that happens only once every ten years. All an
ordinary user has to do is to write a program that solves a set of
equations or sorts a set of numbers. Once this program is written and
tested for various data sets, then the same user or someone else may use
this program with different coefficients or different numbers over and
over again. So, the program is written only once and used for many years.
This is basically what IMSL does. The IMSL programs are written for large or
small data sets and are capable of accepting data in different formats and
from a variety of sources.
One may say, “Well, I can use my $40 hand calculator to solve a simple 3 by
3 linear equation or obtain the square root of say number 3 in a very short
time, so why would I need to write a program and call IMSL to do that?” The
answer is yes, if we are talking about a very simple 3 by 3 equations. What
if instead of a 3 by 3 set of equations we had a 3000 by 3000 complex
(not real) set of equations. Our $40 calculator is not capable of solving
such a set of complex equations, and besides we constantly need to change
the input data and solve the problem again and again, and may need to keep
a good record of each run.
Below are two simple Fortran examples. These two examples generate the input
data and pass it on to a particular IMSL subroutine. The IMSL then looks and
sends the data to the proper routine for analysis. After the problem is
solved, the answers are sent back to the user. For example if the routine
LSLGR is called, IMSL knows that it is receiving a set of linear equations
and should call its equation solver to solve the set of linear equations and
return the answers to the calling program.
FORTRAN EXAMPLE 1
Suppose that we have the following set of 3 by 3 linear equations:
33.0*X1 +16.0*X2 +72.0*X3 =129.0
24.0*X1 10.0*X2 52.0*X3 = 96.0
18.0*X1 11.0*X2 +7.0*X3 = 8.5
And want to solve the above system of equations obtaining the solutions for
X1, X2, and X3. The following Fortran program is chosen from an IMSL book of
examples. Please note that the Fortran program below contains the coefficients
for the above set of equations and passes them to a routine called LSLRG.
Subroutine LSLRG then solves these equations and returns the answers back to
our small test program that we named mcsr.f90. There are print commands in
program mcsr.f90 that print the results out on the terminal. Our job as a
user is to make sure to pass the correct numbers of coefficients to LSLRG
through our test program mcsr.f90. If the input data (data which we pass to
LSLRG) is not correct, we are not going to have correct answers for our
system of equations.
! Declare variables
PARAMETER (IPATH=1, LDA=3, N=3)
REAL A(LDA,LDA), B(N), X(N)
!
! Set values for A and B, values below are not passed to the computer
! and are only a reminder to the programmer.
!
! A = ( 33.0 16.0 72.0)
! (24.0 10.0 57.0)
! ( 18.0 11.0 7.0)
!
! B = (129.0 96.0 8.5)
! In the DATA statement below, values are numerical values are passed on to the
! to the computer.
DATA A/33.0, 24.0, 18.0, 16.0, 10.0, 11.0, 72.0, 57.0, 7.0/
DATA B/129.0, 96.0, 8.5/
!
CALL LSLRG (N, A, LDA, B, IPATH, X)
! Print results
CALL WRRRN ('X', 1, N, X, 1, 0)
END
BEFORE COMPILATION
Before compiling your Fortran or C/C++ program with calls to IMSL routines,
you must make sure certain environment variables are setup: $F90FLAGS and
$LINK_F90. You will use these variables to supply options to the compiler to
ensure that it can find and link in the IMLS library. These environment
variables can be set as follows:
On Willow:
For sh, ksh, or bash users, execute the following command before trying to
compile your program. You can type it at the command line, or to have it
executed automatically each time you log in, add it as the last line in your
.login script in your home directory, then relogin.
. /usr/local/vni/CTT3.0/ctt/bin/cttsetup.sh
Or, for csh or tcsh users, execute the following command before trying to
compile your program. You can type it at the command line, or to have it
executed automatically each time you login, add it as the last line in your
.profile script in hour home directory, then relogin.
source /usr/local/vni/CTT3.0/ctt/bin/cttsetup.csh
On Sweetgum:
For sh, ksh, or bash users, execute the following command before trying to
compile your program. You can type it at the command line, or to have it
executed automatically each time you log in, add it as the last line in your
.profile script in your home directory, then relogin.
. /users/local/appl/imsl/imsl.sh
For csh or tcsh users, your environment should already be set up as needed
by default.
COMPILING YOUR IMSL FORTRAN PROGRAM
The example programs in this article (mcsr.f90 and mcsr2.f90) may be copied
to your working directory from either /users/local/appl/examples/imsl
(on willow) or /usr/local/appl/imsl on sweetgum. To compile the above
Fortran program on willow or sweetgum, first ensure that you have the
steps under the PRECOMPILATION SETUP section above. Then, compile your
program as follows:
f90 $F90FLAGS mcsr.f90 $LINK_F90
Where “mcsr.f90” is the name of the above Fortran Program. If there are no
compiling or linking errors, an executable file named a.out will be created
in your working directory. To run the program, type:
./a.out
The solution obtained from solving the above 3 by 3 linear equations is:

X


1

2

3

1.000

1.500

1.000

FORTRAN EXAMPLE 2
The second example sorts the following data:
1.0 2.0 3.0 4.0 5.0 6.0 7.0 9.0 10.0
The Fortran program is:
!declare Variable
PARAMETER (N=10)
REAL RA(N), RB(N)
!SET VALUES FOR RA
!RA=(1.0 2.0 3.0 4.0 5.0 6.0 7.0 9.0 10.0)
!
DATA RA/1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0/
!
CALL SVRGN (N, RA, RB)
! print results
CALL UMACH(2,NOUT)
WRITE(NOUT,99999) (RB(J),J=1,N)
!
99999 FORMAT(' the output vector is, input after sort is: ',/, 10(1x,f5.1))
END
The output, the input after sorting by the above program is:
9.0 7.0 5.0 3.0 1.0 2.0 4.0 6.0 8.0 10.0
The instruction to execute the above program is the same as the first one.
Users may note that lines starting with “!” in the above Fortran programs are
comments and don’t go through the Fortran compiler. For example the sort
program has 8 lines not counting the comment lines. Users having IMSL or
other technical questions should contact:
assist@mcsr.olemiss.edu.
