Previous | Contents | Index |
This chapter contains the following topics:
The following aspects of Compaq Fortran are relevant to the compilation environment and should be considered before extensive coding begins:
% limit stacksize stacksize 4096 kbytes % limit stacksize 32676 % limit stacksize stacksize 32676 kbytes |
% limit stacksize unlimited |
$ ulimit -s 4096 $ ulimit -s 32676 $ ulimit -s 32676 |
% limit descriptor descriptors 100 files % limit descriptor 4096 % limit descriptor descriptors 4096 files |
$ ulimit -n 2048 $ ulimit -n 4096 $ ulimit -n 4096 |
Example 1-1 shows a short Fortran 95/90 main program using free form source.
Example 1-1 Sample Main Program |
---|
! File hello.f90 PROGRAM HELLO_TEST print *, 'hello world' print *, ' ' END PROGRAM HELLO_TEST |
To create and revise your source files, use a text editor, such as vi or emacs . On Linux systems, the peco editor is available. For instance, to use vi to edit the file hello.f90 , type:
% vi hello.f90 |
The following command compiles the program named hello.f90 and automatically uses ld to link the main program into an executable program file named a.out :
% f90 hello.f90 |
The f90 command (or on Linux systems, the fort command) automatically passes a standard default list of Compaq Fortran Run-Time Libraries to the ld linker. In this example, because all external routines used by this program reside in these standard libraries, additional libraries or object files are not specified on the f90 (or fort ) command line.
If your path definition includes the directory containing a.out , you can run the program by simply typing its name:
% a.out |
If the executable image is in your current directory, specify:
% ./a.out |
If the executable image is not in a directory in your path definition and it is not in your current directory, then specify its full path. For example:
% /usr/disk5/mcdonald/a.out |
Example 1-2 shows a sample Fortran 95/90 main program using free source form that uses a module and an external subprogram.
The function CALC_AVERAGE is contained in a separately created file and depends on the module ARRAY_CALCULATOR for its interface block.
Example 1-2 Sample Main Program that Uses a Module and Separate Function |
---|
! File: main.f90 ! This program calculates the average of five numbers PROGRAM MAIN USE ARRAY_CALCULATOR (1) REAL, DIMENSION(5) :: A = 0 REAL :: AVERAGE PRINT *, 'Type five numbers: ' READ (*,'(F10.3)') A AVERAGE = CALC_AVERAGE(A) (2) PRINT *, 'Average of the five numbers is: ', AVERAGE END PROGRAM MAIN |
Example 1-3 shows the module referenced by the main program. This example program shows more Fortran 95/90 features, including an interface block and an assumed-shape array.
Example 1-3 Sample Module |
---|
! File: array_calc.f90. ! Module containing various calculations on arrays. MODULE ARRAY_CALCULATOR INTERFACE FUNCTION CALC_AVERAGE(D) REAL :: CALC_AVERAGE REAL, INTENT(IN) :: D(:) END FUNCTION CALC_AVERAGE END INTERFACE ! Other subprogram interfaces... END MODULE ARRAY_CALCULATOR |
Example 1-4 shows the function declaration CALC_AVERAGE referenced by the main program.
Example 1-4 Sample Separate Function Declaration |
---|
! File: calc_aver.f90. ! External function returning average of array. FUNCTION CALC_AVERAGE(D) REAL :: CALC_AVERAGE REAL, INTENT(IN) :: D(:) CALC_AVERAGE = SUM(D) / UBOUND(D, DIM = 1) END FUNCTION CALC_AVERAGE |
During the early stages of program development, the sample program files in Example 1-2, Example 1-3, and Example 1-4 might be compiled separately and then linked together, using the following commands:
% f90 -c array_calc.f90 % f90 -c calc_aver.f90 % f90 -c main.f90 % f90 -o calc main.o array_calc.o calc_aver.o |
In this sequence of f90 (or fort ) commands:
To allow more optimizations to occur (such as the inline expansion of called subprograms), the entire set of three source files can be compiled and linked together with a single f90 command:
% f90 -o calc array_calc.f90 calc_aver.f90 main.f90 |
The order in which the file names are specified is significant. This f90 command:
If your path definition includes the directory containing calc , you can run the program by simply typing its name:
% calc |
When running the sample program, the PRINT and READ statements in the main program result in the following dialogue between user and program:
Type five numbers: 55.5 4.5 3.9 9.0 5.6 Average of the five numbers is: 15.70000 |
To debug a program with the Compaq Ladebug Debugger, compile the source files with the -g and -ladebug options to request additional symbol table information for source line debugging in the object and executable program files. The following f90 command also uses the -o option to name the executable program file calc_debug :
% f90 -g -ladebug -o calc_debug array_calc.f90 calc_aver.f90 main.f90 |
The Ladebug debugger has a character-cell interface ( ladebug command) and a windowing interface.
For instance, to use the character-cell interface to debug an executable program named calc_debug on a system running Compaq Tru64 UNIX, type the following command:
% ladebug calc_debug |
The Compaq Tru64 UNIX operating system provides the Ladebug debugger and the dbx debugger, both of which can be used to debug Compaq Fortran programs. On Linux Alpha systems, the Compaq Fortran CD-ROM includes the Ladebug debugger.
For more information about Ladebug, see the following Web site:
http://www.compaq.com/products/software/ladebug/ |
For more information on running the program within the debugger, see
Chapter 4, Using the Ladebug Debugger.
1.4 f90 or fort Command and Related Software Components
Compaq Fortran provides the standard features of a compiler and linker. Compaq Fortran also supports the use of preprocessors and other compilers.
Compiling and linking are usually done by a single f90 or fort command. The f90 or fort command allows you to use:
The f90 or fort command invokes a driver program that is the actual user interface to the Compaq Fortran compiler. It accepts a list of command-line options and file names, and causes one or more programs (preprocessor, compiler, assembler, or linker, executed in a sequential manner) to process each file.
After the Compaq Fortran compiler processes the appropriate files to create one or more object files, the driver program passes a list of files, certain options, and other information to the cc (or, on Linux systems, the ccc ) compiler.
The cc compiler processes relevant non-Fortran files and information (including running the cpp preprocessor) and passes certain information (such as .o object files) to the ld linker. The cc compiler applies cpp to files that it recognizes, such as any file with a .c suffic. If cpp is used, it is executed once for each file.
If any program does not return a normal status, further processing is discontinued and the f90 command displays a message identifying the program (and its returned status, in hexadecimal) before terminating its own execution.
See Figure 2-1, Driver Programs and Software Components.
1.4.2 cpp, fpp, and Other Preprocessors
When you use a preprocessor for Compaq Fortran source files, the output files the preprocessor creates are used as input source files by the Compaq Fortran compiler. Preprocessors include:
The Compaq Fortran compiler provides the following primary functions:
The object file created by the compiler contains information used by the linker, including the following:
The file name of the Compaq Fortran compiler is
decfort90
, which may appear in certain messages.
1.4.4 Other Compilers
You can compile and link multilanguage programs using a single f90 command.
The f90 command recognizes C or Assembler program files by their file suffix characters and passes them to the cc driver and compiler for compilation. Before compilation, cc applies the cpp preprocessor to files that it recognizes, such as any file with a .c suffix, and passes appropriate files to other compilers or the assembler.
Certain options passed to
cc
are passed by
cc
to the
ld
linker.
1.4.5 Linker (ld)
When you enter an f90 command, the ld linker is invoked automatically unless a compilation error occurs or you specify the -c option on the command line. The linker produces an executable program image with a default name of a.out .
The ld linker provides such primary functions as:
For more information, see ld(1) and your
operating system's programmer's guide.
1.5 Program Development Stages and Tools
This manual primarily addresses the program development activities associated with implementation and testing phases. For information about topics usually considered during application design, specification, and maintenance, see your operating system documentation, appropriate reference pages, or appropriate commercially published documentation.
Table 1-1 lists and describes some of the software tools you can use when implementing and testing a program.
Task or Activity | Tool and Description |
---|---|
Manage source files | Use rcs or sccs to manage source files. For more information, see the Compaq Tru64 UNIX Using Programming Support Tools or the appropriate reference page. |
Create and modify source files | Use a text editor, such as vi or emacs . For more information, see your operating system documentation. |
Analyze source code | Use searching commands such as grep and diff . For more information, see the Compaq Tru64 UNIX Using Programming Support Tools and the appropriate reference page. |
Build program (compile and link) | You can use the f90 command to create small programs, perhaps using shell scripts, or use the make command to build your application in an automated fashion using a makefile. For more information on f90 , see Chapter 2. For more information on make , see the make(1) reference page and the Compaq Tru64 UNIX Using Programming Support Tools. |
Debug and Test program | Use Ladebug (or dbx) to debug your program or run it for general testing. For more information on debugging, see Chapter 4. |
Analyze performance |
To perform profiling of code, use the
prof
and
pixie
(TU*X ONLY)
programs. The
f90
command option needed to use
prof
is
-p
(same as
-p1
).
To perform call graph profiling, use the gprof tool. The f90 command option needed to use gprof is -pg . Related profiling tools (TU*X ONLY) include the use of feedback files and -cord . For more information on profiling Fortran 90 code, see Chapter 5. |
Install program
(TU*X ONLY) |
Use setld and related commands such as tar . For more information, see the Compaq Tru64 UNIX Using Programming Support Tools. |
To view information about an object file or an object library, use the following shell commands:
For more information on these commands, see the appropriate reference page or the operating system's programmer's guide.
To perform other program development functions at various stages of program development:
Compaq Fortran conforms to American National Standard Fortran 95 (ANSI X3J3/96-007) 1 and American National Standard Fortran 90 (ANSI X3.198-1992) 2, and includes support for the OpenMP Fortran 1.1 Application Program Interface 3 and the High Performance Fortran Language Specification 4.
The ANSI committee X3J3 is currently answering questions of interpretation of Fortran 95 and Fortran 90 language features. Any answers given by the ANSI committee that are related to features implemented in Compaq Fortran may result in changes in future releases of the Compaq Fortran compiler, even if the changes produce incompatibilities with earlier releases of Compaq Fortran.
Compaq Fortran also includes support for programs that conform to the previous Fortran standards (ANSI X3.9-1978 and ANSI X3.0-1966), the International Standards Organization standard ISO 1539-1980 (E), the Federal Information Processing Institute standard FIPS 69-1, and the Military Standard 1753 Language Specification.
Compaq Fortran provides a number of extensions to the Fortran 95/90 standards. Compaq Fortran extensions to the Fortran 95/90 standards are generally provided for compatibility with Compaq Fortran extensions to the ANSI FORTRAN-77 standard and to support the High Performance Fortran (HPF) Language Specification.
When creating new programs that need to be standard-conforming for portability reasons, you should avoid or minimize the use of extensions to the Fortran 95/90 standards. Extensions to the Fortran 95/90 standards are identified visually in the Compaq Fortran Language Reference Manual, which defines the Compaq Fortran language.
1 This is the same as International Standards Organization standard ISO/IEC 1539-1:1997 (E).2 This is the same as International Standards Organization standard ISO/IEC 1539:1991 (E).3 See the specification at http://www.openmp.org/specs/.4 See High Performance Fortran Language Specification, Version 1.1, Technical Report CRPC-TR-92225, Center for Research on Parallel Computation, Rice University, Houston, Texas, USA. |
Previous | Next | Contents | Index |