6.5.1 Inlining Example

The following example demonstrates inlining with /inline=setup , where only the function setup will be inlined, and with /inline , where both functions are inlined. The KAP output includes optimized versions of both functions, in addition to the expanded main program, as follows:

Source file (before the C preprocessor):

#include <math.h>
#include <stdio.h>
#define  SIZE  200

main ()
{
int i,n;
double a[SIZE][SIZE], b[SIZE][SIZE], c[SIZE][SIZE];
double cksum, matm();

setup(b,SIZE);
setup(c,SIZE);

  for (n=25; n<=SIZE; n=n+25)
  {
  cksum = matm(n,a,b,c);
  printf("For N=  %d   checksum= %g \n", n, cksum);
   }
   }

setup (e,n)
double e[SIZE][SIZE];
int    n;
 {
   int    i,j;
    for(i=0; i<n; i++)
  {
   for (j=0; j<n; j++)
   e[i][j] = ( (i+ 7*j) % 10 )/10.0;
  }
return;
  }

double matm (n,a,b,c)
int    n;
double a[SIZE][SIZE], b[SIZE][SIZE], c[SIZE][SIZE];
 {
 int i,j,k;

 for (i=0; i<n; i++)
 for (j=0; j<n; j++)
  {
    a[i][j] = 0.0 ;
    for (k=0; k<n; k++)
    a[i][j] = a[i][j] + b[i][k]*c[k][j];
     }

return (a[3][5]);
       }

The main function generated by /inline=setup is as follows:

int main(  )

 {
  int i;
  int n;
  double a[200][200];
  double b[200][200];
  double c[200][200];
  double cksum;
  double matm( );
  int _Kii3;
  int j;
  int _Kii6;
  int _Kii7;

     for ( _Kii3 = 0; _Kii3<=199; _Kii3++ ) {
       for ( j = 0; j<=199; j++ ) {
      b[_Kii3][j] = ((_Kii3 + j * 7) % 10) / 10.0;
         }
          }
     for ( _Kii6 = 0; _Kii6<=199; _Kii6++ ) {
       for ( _Kii7 = 0; _Kii7<=199; _Kii7++ ) {
        c[_Kii6][_Kii7] = ((_Kii6 + _Kii7 * 7) % 10) / 10.0;
     }
    }
       for ( n = 25; n<=200; n+=25 ) {
     cksum = matm( n, a, b, c );
     printf( "For N=  %d   checksum= %g \n", n, cksum );
    }
      }

The main function generated by /inline is as follows:

int main(  )

 {
 int i;
 int n;
 double a[200][200];
 double b[200][200];
 double c[200][200];
 double cksum;
 double matm( );
 double _Kaa1;
 int _Kii2;
 int j;
 int k;
 int _Kii5;
 int _Kii6;
 int _Kii9;
 int _Kii10;

    for ( _Kii5 = 0; _Kii5<=199; _Kii5++ ) {
      for ( _Kii6 = 0; _Kii6<=199; _Kii6++ ) {
       b[_Kii5][_Kii6] = ((_Kii5 + _Kii6 * 7) % 10) / 10.0;
     }
   }
    for ( _Kii9 = 0; _Kii9<=199; _Kii9++ ) {
      for ( _Kii10 = 0; _Kii10<=199; _Kii10++ ) {
     c[_Kii9][_Kii10] = ((_Kii9 + _Kii10 * 7) % 10) / 10.0;
     }
    }
    for ( n = 25; n<=200; n+=25 ) {
      for ( _Kii2 = 0; _Kii2<n; _Kii2++ ) {
       for ( j = 0; j<n; j++ ) {
       a[_Kii2][j] = 0.0;
      for ( k = 0; k<n; k++ ) {
     a[_Kii2][j] +=  b[_Kii2][k] * c[k][j];
       }
      }
      }
    _Kaa1 = a[3][5];
    cksum = _Kaa1;
    printf( "For N=  %d checksum= %g \n", n, cksum );
   }
   }


Previous Page Next Page Contents Index
Command-Line Qualifiers