This chapter describes the basic elements of the HPF/Fortran 90 language, the format of Fortran statements, and the types of expressions and assignments accepted by pghpf Workstation HPF product. The pghpf compiler is an HPF compiler that accepts as input HPF and outputs object code or executables in conjunction with the native Fortran 77 compilation system on the target platform. The pghpf compiler supports many different targets (see the release notes for supported platforms). The input language must be HPF, conforming to the Fortran language specified in this reference manual.
This chapter is not an introduction to the capabilities of HPF for data distribution, communications or parallelism. Rather, this chapter is an overview of the syntax requirements of programs used with the Fortran compiler. The pghpf User's Guide and The High Performance Fortran Handbook provide details on the capabilities of Fortran 90 and the HPF language.
A Fortran program unit is either a SUBROUTINE, FUNCTION, MODULE, BLOCK DATA, or PROGRAM subprogram.
Fortran source consists of a sequence of program units which are to be compiled. Every program unit consists of statements and optionally comments beginning with a program unit statement, either a SUBROUTINE, FUNCTION, or PROGRAM statement, and finishing with an END statement (BLOCK DATA and MODULE program units are also allowed).
In the absence of one of these statements, the compiler inserts a PROGRAM statement.
Statements are either executable statements or nonexecutable specification statements. Each statement consists of a single line or source record, possibly followed by one or more continuation lines. Multiple statements may appear on a single line if they are separated by a ; (semicolon). Comments may appear on any line following a comment character (!).
Fortran permits two types of source formatting, free source form and fixed source form. Free source form places few restrictions on source formatting; the context of an element, as well as the position of blanks, or tabs, separate logical tokens. Fixed source form uses the traditional Fortran approach where specific column positions are reserved for labels, continuation characters, and statements and blank characters are ignored. The pghpf compiler also supports a less restrictive variety of fixed source form called tab source form. Using the compiler option -Mfreeform you can select free source form as an option.
Table 1-1 shows the Fortran character set. Character variables and constants can use any ASCII character. The value of the command-line option -Mupcase determines if the compiler distinguishes between case (upper and lower) in identifiers. By default, without the -Mupcase option selected, the compiler does not distinguish between upper and lower case characters in identifiers (upper and lower case are always significant in character constants).
Table 1-1 Fortran Characters
1.3 Free Form Formatting
Using free form formatting, columns are not significant for the elements of a Fortran line, and a blank or series of blanks or tabs and the context of a token specify the token type.
Using free formatting 132 characters are valid per line, and the compiler option -Mextend does not apply.
Comments are indicated by a blank line, or by following a Fortran line with the ! character. All characters after the ! are stripped out of the Fortran text.
Using free formatting the & character at the end of a line means the following line represents a continuation line. If a continuation line starts with a & character, then the characters following the & are the start of the continuation line, without a & at the start of the continuation line, all characters on the line are part of the continuation line, including any initial blanks or tabs.
A single Fortran line may contain multiple statements. The ; (semicolon) separates multiple statements on a single line.
Free format labels are valid at the start of a line, as long as the label is separated from the remaining statements on the line by at least one blank or a <TAB>. Labels consist of a numeric field drawn from digits 0 to 9. The label cannot be more than 5 characters.
This section describes the two types of fixed formatting that pghpf supports, column formatting and tab formatting.
Using column formatting a Fortran record consists of a sequence of up to 73 ASCII characters, the last being <CR>. There is a fixed layout as shown in Table 1-2.
Table 1-2 Fixed Format Record Positions and Fields
Characters beyond position 72 on a line are ignored unless the -Mextend option is specified. In addition, any characters following a ! character are comments and are disregarded during compilation.
The label field holds up to five characters. The characters C or * in the first character position of a label field indicate a comment line.
In addition to the characters C or *, either of the characters D or ! in the first position of a label field also indicate a comment line.
When a numeric field drawn from digits 0 to 9 is placed in the label field, the field is a label. A line with no label, and with five space characters or a <TAB> in the label field, is an unlabeled statement. Each label must be unique in its program unit. Continuation lines must not be labeled. Labels can only be jumped to when they are on executable statements.
The sixth character position, or the position after the tab, is the continuation field. This field is ignored in comment lines. It is invalid if the label field is not five spaces. A value of 0, <space> or <TAB> indicates the first line of a statement. Any other value indicates a subsequent, continuation line to the preceding statement.
The statement field consists of valid identifiers and symbols, possibly separated by <space> or <TAB> and terminated by <CR>.
Within the statement field tabs and spaces are ignored as are comments, characters following a !, or any characters found beyond the 72nd character (unless the option -Mextend is enabled).
The letter D in column 1 using fixed formatting designates the statement on the specified line is a debugging statement. The compiler will treat the debugging statement as a comment, that is ignore it, unless the command line option-Mdlines is set during compilation. In that case, the compiler acts as if the line starting with D were a Fortran statement and compiles the line according to the standard rules.
The pghpf compiler supports an alternate form of fixed source from called tab source form. A tab formatted source file is made up of a label field, an optional continuation indicator and a statement field. The label field is terminated by a tab character. The label cannot be more than 5 characters.
A continuation line is indicated by a tab character followed immediately by a digit. The statement field starts after a continuation indicator, when one is present. The 73rd and subsequent characters are ignored.
The sequence of consecutive compilation of source statements may be interrupted so that an extra source file can be included. This is carried out using the INCLUDE statement which takes the form:
INCLUDE "filename"where filename is the name of the file to be included. Pairs of either single or double quotes are acceptable enclosing filename.
The INCLUDE file is compiled to replace the INCLUDE statement, and on completion of that source the file is closed and compilation continues with the statement following the INCLUDE.
For example the following statement includes the file MYFILE.DEF.
INCLUDE "MYFILE.DEF"Recursive includes are not allowed. That is, if a file includes a file, that file may not also include the same file.
Nested includes are allowed, up to a pghpf defined limit of 20.
Fortran program units are made up of statements which consist of expressions and elements. An expression can be broken down to simpler expressions and eventually to its elements combined with operators. Hence the basic building block of a statement is an element. An element takes one of the following forms:
Symbolic names identify different entities in HPF source. A symbolic name is a string of letters and digits, which must start with a letter and be terminated by a character not in the symbolic names set (for example a <space> or a <TAB> character). Underscore (_) characters may appear within symbolic names. Only the first thirty-one characters identify the symbolic name. Below are several symbolic names:
The last example is identified by its first 31 characters and is equivalent to:
numericabcdefghijklmnopqrstuvwxThe following examples are invalid symbolic names.
8QThis is invalid because it begins with a number.
FIVE.4This is invalid because it contains a period which is an invalid character for a symbolic name.
Each data item, such as a variable or a constant, represents a particular value at any point during program execution. These elements may be combined together to form expressions, using binary or unary operators, so that the expression itself yields a value. A Fortran expression may be any of the following:
Arithmetic, relational and logical expressions may be identified to the compiler by the use of parentheses, as described in the section on arithmetic expressions. When no guidance is given to the compiler it will impose a set of precedence rules to identify each expression uniquely. Table 1-3 shows the operator precedence rules for expressions.
Table 1-3 Fortran Operator Precedence
+ or -
+ or -
operators: GT., .GE., .LE.
operators ==, /=
operators <, <=, >, >=
operators .EQ., .NE., .LT.
A*B+B**C .EQ. X+Y/Z .AND. .NOT. K-3.0 .GT. T
((((A*B)+(B**C)) .EQ. (X+(Y/Z))) .AND. (.NOT. ((K-3.0) .GT. T)))
1.8 Symbolic Name Scope
Fortran 90 scoping is expanded from the traditional Fortran 77 capabilities which provide a scoping mechanism using subroutines, main programs, and COMMONs. Fortran now adds the MODULE statement. Modules provide an expanded alternative to the use of both COMMONs and INCLUDE statements. Modules allow data and functions to be packaged and defined as a unit, incorporating data hiding and using a scope that is determined with the USE statement.
A Fortran assignment statement can be any of the following:
The HPF compiler recognizes three compiler directives that affect the program listing process:
All of the directives must begin in column one.
Directives in a Fortran program provide information that allows the pghpf compiler to explicitly determine data distribution from which parallelism can be derived. An HPF directive may have any of the following forms:
CHPF$ directive !HPF$ directive *HPF$ directiveSince HPF supports two source forms, fixed source form and free source form, there are a variety of methods to enter a directive. The C, !, or * must be in column 1 for fixed source form directives. In free source form, Fortran limits the comment character to !. If you use the !HPF$ form for the directive origin, your code will be universally valid. The body of the directive may immediately follow the directive origin. Alternatively, any number of blanks may precede the HPF directive. Any names in the body of the directive, including the directive name, may not contain embedded blanks. Blanks may surround any special characters, such as a comma or an equals sign.
The directive name, including the directive origin, may contain upper or lower case letters (case is not significant). For details on the valid HPF directives refer to Chapter 4, HPF Directives.