Compaq KAP C/OpenMP for Tru64 UNIX

Compaq KAP C/OpenMP
for Tru64 UNIX

User Guide



Order Number: AA--PXEFK--TE


June 2000

This document provides information about how to run and use Compaq KAP C/OpenMP on Compaq Tru64 UNIX systems.

Revision/Update Information: This is a revised document.

Operating System and Version: Compaq Tru64 UNIX Versions 4.0F, 5.0, and 5.0A

Software Versions: Version 4.1
Compaq C Version 6.1

Compaq Computer Corporation
Houston, Texas


© 1993 Compaq Computer Corporation

© 1993 Kuck & Associates, Inc.

Compaq, the Compaq logo, Compaq C, and Compaq Fortran, Registered in U.S. Patent and Trademark Office.

KAP is a trademark of Kuck & Associates, Inc.

UNIX is a registered trademark of The Open Group.

All other product names mentioned herein may be trademarks or registered trademarks of their respective companies.

Compaq shall not be liable for technical or editorial errors or omissions contained herein. The information in this document is subject to change without notice. This document is available on CD-ROM.

Contents Index


Preface

This document describes how to use Compaq KAP C/OpenMP software on Compaq Tru64 UNIX systems.

Intended Audience

This document is a guide for KAP users working with Compaq C on Compaq Tru64 UNIX systems.

Structure of This Document

This document is organized into the following chapters and appendixes:

Associated Documents

This document is part of the KAP document set that also includes:

Conventions

The following are equivalent terms used in this document:

The following table lists the other conventions used in this guide.
Convention Description
< > Angle brackets denote command input you replace with the appropriate value.
( ) Parentheses containing a single command value denote the default value. For example, (-optimize=5) denotes 5 is the default value.

Parentheses containing hyphenated value ranges denote that you choose a value from the range.

[ ] Square brackets indicate optional syntax. For example:
#pragma _KAP [no]inline [(name)]
UPPERCASE and lowercase The Tru64 UNIX system differentiates between lowercase and uppercase characters. Literal strings that appear in text, examples, syntax descriptions, and function descriptions must be typed exactly as shown.
italic type Italic type indicates complete titles of manuals and keywords, as well as product names.


Chapter 1
Overview

KAP for C is a source-to-source preprocessor that restructures C code for improved performance and better utilization of the memory hierarchy of Tru64 UNIX systems. Additionally, KAP performs parallel decomposition to take advantage of shared memory and symmetric multiprocessors. By eliminating inefficiencies and bottlenecks, KAP enables you to get your answers faster without time-consuming, hand-recoding of applications programs.

Because KAP makes it possible to run serial C programs efficiently on advanced architecture computers without hand-recoding, the original programs remain portable and users need not concern themselves with the details of each machine.

KAP optimizations include:

The KAP conversion process is designed to operate effectively without intervention from you. KAP provides a large set of command-line switches and inline assertions and directives that the advanced user can use for even better performance on specific codes. The optional KAP listing file includes information that identifies the parts of the source program that could benefit from such attention.


Chapter 2
How to Run KAP

This chapter gives general information about KAP syntax, file-naming conventions, and optimizing programs with KAP. Sections describing how to compile and run programs with KAP are specific to single-processor Tru64 UNIX systems. For information on how to compile and run programs with KAP on multiprocessor systems, see Chapter 3.

Compaq KAP C/OpenMP for Tru64 UNIX can be run in either of two modes:

2.1 Using KAP

The following command-line switches provide maximum general optimization: -optimize=5, -roundoff=3, and -scalaropt=3. These are the default settings for these switches.

See Section 2.3 for an explanation of how to pass command-line switches to KAP and Chapter 4 for details about what is controlled by each switch's levels.

2.2 Installing KAP

KAP is installed on the Tru64 UNIX system with the system command setld. See the Compaq KAP C/OpenMP for Tru64 UNIX Installation Guide for details.

The directory that contains the executable KAP file must be in your path; or a command such as kapc must be aliased to point to the executable file.

If you are a frequent user of KAP, you may find it convenient to add an alias to your .cshrc files so that a kapc command with preferred switches is available. Contact your system manager for the directory location of the executable KAP file.

2.3 Compiling a Program Using the kcc Driver

The kcc command invokes a driver program that automatically calls KAP, the C compiler, and the linker. The following examples show how to use kcc:

2.4 Saving Optimized Source Programs

The kcc command saves the optimized version of your source program followed by the extension .cmp.c in the source directory for use in debugging and profiling. You can override the KAP default of adding .cmp.c to the source program name with the -cmp switch. See Section 4.7.1 for more information.

2.5 KAP Command Switches Determined by Compiler Switches

Some C compiler switches automatically set KAP command switches or alter the default switch settings.

Explicitly calling the compiler switch -std1 causes KAP to be called with the command switch -syntax=a.

Explicitly calling the compiler switch -standard=common causes KAP to be called with the command switch -syntax=k.

Calling the C compiler without any compiler switches or with the compiler switch -std0 causes KAP to be called with the command switch -syntax=d.

2.6 Invoking the C Preprocessor

The kcc command invokes the C preprocessor before transforming a file with KAP. The name __KAP is defined for the C preprocessor in order to include alternate code in some system include files. Commands with the preprocess-only switch will terminate after the C preprocessor phase.

2.7 Preprocessing a Program Using kapc

For C programs that do not contain C preprocessor commands such as #define, #include, #ifdef, or macro definitions, use the following command to execute KAP as a standalone preprocessor:


kapc [kap_switch_string]  myprog.c -cmp=myprog.cmp.c 

The [kap_switch_string] is a list of one or more KAP command switches, for example:


kapc -inm -roundoff=2 myprog.c -cmp=myprog.cmp.c 

For C programs that contain C preprocessor commands, the input file must first be preprocessed with the C compiler. Use the following commands:


cc -P -D__KAP -U_INLINE_INTRINSICS myprog.c 
kapc -cmp=myprog.cmp.c myprog.i 

After preprocessing your program, give the optimized source file myprog.cmp.c to the compiler, as follows:

For an explanation of the -migrate, -tune host, -lkio, -fast, and -U_INLINE_INTRINSICS switches, see Section 2.3.

Note

When you use kapc to process a file, you must set the Compaq C compiler and linker switches appropriately. For this reason, Compaq recommends that you use kcc whenever possible, because kcc automatically sets the compiler and linker switches correctly.

2.8 Using KAP Syntax

Specify switches in lowercase with the syntax -switch[=value]. Do not leave spaces between the switch name and the value. Switches can appear before or after the input file as follows:


kapc -inm  myprog.c  -roundoff=2 

KAP recognizes standard abbreviations for switches. Switches that take a list of names must have the names separated by commas and without spaces, for example:


-inff=file1.c,file2.c 

Enclose KAP command switches passed through kcc by using the -ckapargs switch with single quotation marks, as follows:


kcc -ckapargs='-optimize=5  -roundoff=3  -scalaropt=3' -list myprog.c 

C compiler switches, for example, -list, do not require quotation marks.

2.9 Using File Naming Conventions

Any input file name is acceptable. Output file names are written to stdout unless the -cmp command switch is specified.

When KAP detects an error condition, KAP writes a message to standard error.

2.10 Introducing the Five-Minute KAP Guide

This section describes how you can get maximum performance in your application programs in the shortest time.

This information can be used with both multiprocessor and single-processor systems, and with both Fortran and C versions of all KAP products. Therefore, the information may contain references to command-line switches or settings that are unavailable or are different from those in the KAP that you are using.

This section provides separate protocols for small and large programs. Small programs are defined as those that can be compiled and run quickly. Because the cost of each iteration is small, you can take risks. The information presented here further assumes that small programs have a small number of program units.

Large programs are defined as those that take more time to compile and run than it takes for you to check the results. A program can be large either because the source code is very large or because the execution time is long.

2.10.1 Optimizing Small Programs with KAP

Follow these guidelines to optimize small programs:

  1. Compile the program without KAP, with minimum compiler optimization, and with all compiler run-time checks enabled. Note the execution time and verify the results. If the program fails at this step, there is little optimization you can do.
    Some older programs use standard-violating techniques that KAP will not transform safely. If KAP fails because of this problem, you cannot do much optimization.
    If you have the time and you know what the program is supposed to do, you can try to isolate the incorrect code, correct it, and proceed. This action may not be feasible for handling problems in large programs, but it might work for isolated portability problems.
    If the problem code is isolated and runs without KAP optimization, you may be able to use KAP on the rest of the program and leave out any problematic sections.
    You can also refer to Section 2.13. You may be able to diagnose and correct some problems, and then run KAP on your program successfully.
  2. Compile without KAP but with maximum compiler optimization. Note the execution time and verify the results. If the program fails, reduce compiler optimization and try again.
  3. Compile the fastest or best run without using KAP and run it again with profiling enabled (for example, gprof) to identify the program units that take the most time to run.
    If some time-intensive units have many iterative loops and arrays, then those units are good candidates for KAP loop optimizations. Go to step 4.
    If the units are not good candidates, lower-payoff optimizations, such as inlining, may provide some performance improvement, especially where inlining inside loop nests may also allow KAP to perform vectorization optimizations. If this is the case, go to step 6.
  4. If the program compiles with minimum compiler optimization enabled, then turn on all optimization except inlining by invoking -optimize=4 and full compiler optimization.
  5. If step 2 succeeds and the results are correct, try the suggestions described in the Section 2.12.
  6. If step 2 fails, try reducing one optimization at a time (-roundoff=0, -scalaropt=1, -optimize=3, and any compiler optimizations) until the program runs correctly. Use the -lo=k switch setting to create a listing of the KAP command-line switches and settings.


Next Contents Index