7.4.2 Inlining Example with a Library

The following example demonstrates the creation of a library and inlining routines from it; a two-step process:

Step 1: Create the library.

SUBROUTINE  MKCOEF (COEF,N)
  REAL COEF(N)
  DO 99 I = 1,N
  COEF(I) = 1.0/I
99   CONTINUE
  RETURN
  END

  REAL FUNCTION YVAL (X, COEF, N)
  REAL COEF(N), X, SUM
  SUM = 0.0
  DO 99 I=1,N
  SUM = SUM + COEF(I) * SIN(I*X)
99   CONTINUE
  YVAL = SUM
  RETURN
  END

If the file subfil.f contains the previous two routines, then executing the KAP command, KAP /inline_create subfil.f will create a library file subfil.klib with the two routines, and a listing file subfil.out that contains only a list of routines and whether or not each was saved in the library:

subroutine MKCOEF -- saved
function YVAL -- saved

Step 2: Inline the routines into a calling program.

  PROGRAM  LIBCR
  PARAMETER (NC = 15)
  PARAMETER (PI = 3.141593)
  REAL COEF(NC), YVAL, Y(2000)

  CALL MKCOEF (COEF, NC)
  DO 900 I = 1,2000
  Y(I) = YVAL( I*0.001*PI, COEF, NC)
900  CONTINUE
  J=1
  DO 910 I=1,2000,10
  PRINT *, (Y(J),J=I,I+9)
910  CONTINUE
END

If the file sqwv.f contains the main program LIBCR , then running the command KAP /inline /infl=subfil.klib /inll=2 /o=0 /r=0 /so=0 sqwv.f will put the following into the file sqwv.cmp:

  PROGRAM LIBCR
  PARAMETER (NC = 15)
  PARAMETER (PI = 3.141593)
  REAL COEF(NC), YVAL, Y(2000)
  SAVE J
  REAL RR1, RR2, RR3
  INTEGER II1, II2
  DO 3 II2=1,NC
  COEF(II2) = 1.0 / II2
3 CONTINUE

  DO 900 I=1,2000
  RR1 = I * 0.001 * PI
  RR2 = 0.0
  DO 2 II1=1,NC
  RR2 = RR2 + COEF(II1) * SIN (II1 * RR1)
  2 CONTINUE
  RR3 = RR2
  Y(I) = RR3
900  CONTINUE

  J=1
  DO 910 I=1,2000,10
    PRINT *, (Y(J),J=I,I+9)
910  CONTINUE
  END

In the previous example, all other optimizations were turned off to show the expansion more clearly. If you specify nonzero values for the /optimize , /scalaropt , and /roundoff qualifiers, KAP first inlines the routines, then performs the optimizations in the usual manner.


Previous Page | Next Page | Contents | Index |
Command-Line Qualifiers