Skip to content. Skip to navigation

ICTP Portal

Sections
You are here: Home Manuals on-line PGI Compiler pghpf_ref PGHPF Workstation Reference Manual - 1 Language Overview
Personal tools
Document Actions

PGHPF Workstation Reference Manual - 1 Language Overview

<< << " border=0> >> > " border=0> Title Contents Index Home Help

1 Language Overview


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.

1.1 Elements of a Fortran Program Unit

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.

1.1.1 Statements and Comments

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 (!).

1.1.2 Free and Fixed Source

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.

1.2 The Fortran Character Set

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

Character

Description
Character
Description
,
Comma
A-Z, a-z
Alphabetic
:
Colon
<space>
Space character
;
Semicolon
=
Equals
_
Underscore character
+
Plus
<
Less than
-
Minus
>
Greater than
*
Asterisk
?
Question mark
/
Slash
%
Percent
(
Left parenthesis
"
Quotation mark
)
Right parenthesis
$
Currency symbol
[
Left bracket
.
Decimal point
]
Right bracket
!
Exclamation mark
<CR>
Carriage return
0-9
Numeric
<TAB>
Tabulation character

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.

1.4 Fixed Formatting

This section describes the two types of fixed formatting that pghpf supports, column formatting and tab formatting.

1.4.1 Column 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

Position

Field
1-5
Label field
6
Continuation field
7-72
Statement field

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.

1.4.2 Fixed Format Label Field

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.

1.4.3 Fixed Format Continuation Field

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.

1.4.4 Fixed Format Statement Field

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).

1.4.5 Fixed Format Debug Statements @

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.

1.4.6 Tab Formatting @

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.

1.4.7 Fixed Input File Format Summary

  • Tab-Format lines are supported. A tab in columns 1-6 ends the statement label field and begins an optional continuation indicator field. If a non-zero digit follows the tab character, the continuation field exists and indicates a continuation field. If anything other than a non-zero digit follows the tab character, the statement body begins with that character and extends to the end of the source statement. Note that this does not override Fortran's free source form handling since no valid Fortran statement can begin with a non-zero digit. The tab character is ignored if it occurs in a line except in Hollerith or character constants.
  • Input lines may be of varying lengths. If there are fewer than 72 characters, the line is padded with blanks; characters after the 72nd are ignored unless you use the -Mextend option on the command line.
  • If the -Mextend option is used on the command line then the input line can extend to 132 characters. The line is padded with blanks if it is fewer than 132 characters; characters after the 132nd are ignored. Note that use of this option extends the statement field to position 132.
  • Blank lines are allowed at the end of a program unit.
  • The number of continuation lines allowed is extended from the HPF specification (39 lines for fixed format) to 99 lines.

1.5 Including Fortran Source Files

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.

1.6 The Components of Fortran Statements

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:

  • A constant represents a fixed value.
  • A variable represents a value which may change during program execution.
  • An array is a group of values that can be referred to as a whole, as a section, or separately. The separate values are known as the elements of the array. The array has a symbolic name.
  • A function reference or subroutine reference is the name of a function or subroutine followed by an argument list. The reference causes the code specified at function/subroutine definition to be executed and if a function, the result is substituted for the function reference.

1.6.1 Symbolic Names

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:

NUM

CRA9
Y
numericabcdefghijklmnopqrstuvwxyz


The last example is identified by its first 31 characters and is equivalent to:

numericabcdefghijklmnopqrstuvwx	
The following examples are invalid symbolic names.
8Q	
This is invalid because it begins with a number.
FIVE.4	
This is invalid because it contains a period which is an invalid character for a symbolic name.

1.7 Expressions

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:

  • A scalar expression
  • A array expression
  • A constant expression
  • A specification expression
  • A initialization expression
  • Mixed array and scalar expressions

1.7.1 Expression Precedence Rules

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

Operator

Evaluated
Unary defined
Highest
**

* or /

Unary + or -

Binary + or -

Relational operators: GT., .GE., .LE.

Relational operators ==, /=
same precedence
Relational operators <, <=, >, >=
same precedence
Relational operators .EQ., .NE., .LT.
same precedence
.NOT.

.AND.

.OR.

.NEQV. and .EQV.

Binary defined
Lowest
Operators of equal rank are evaluated left to right. Thus:
	 A*B+B**C .EQ. X+Y/Z .AND. .NOT. K-3.0 .GT. T 
is equivalent to:
	((((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.

1.9 Assignment Statements

A Fortran assignment statement can be any of the following:

  • An intrinsic assignment statement
  • A statement label assignment
  • An array assignment
  • A masked array assignment
  • A pointer assignment
  • A defined assignment

1.10 Listing Controls

The HPF compiler recognizes three compiler directives that affect the program listing process:

%LIST
Turns on the listing process beginning at the following source code line.
%NOLIST
Turns off the listing process (including the %NOLIST line itself).
%EJECT
Causes a new listing page to be started.
These directives have an affect only when the -Mlist option is used.

All of the directives must begin in column one.

1.11 HPF Directives

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$	directive
Since 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.


<< << " border=0> >> > " border=0> Title Contents Index Home Help

Powered by Plone This site conforms to the following standards: