Full HTML for

Basic foilset CPS615 Foils -- Fortran 90 Language and Simple Examples

Given by Nancy McCracken and Geoffrey C. Fox at CPS615 Basic Simulation Track for Computational Science on Fall Semester 95. Foils prepared 21 Sept 1995
Outside Index Summary of Material


This introduces array notation and describes basic array operators
Array Constructors and Array Sections
The Where Construct
Forall available in some compilers and critical for parallelism
Subroutines and Interfaces
Intrinsic Functions
A simple Gauss-Jordan Matrix Inversion is used as an example

Table of Contents for full HTML of CPS615 Foils -- Fortran 90 Language and Simple Examples

Denote Foils where Image Critical
Denote Foils where HTML is sufficient

1 Introduction to Fortran90
for CPS615 Fall 95

2 Abstract of Fortran90 Overview for CPS615
3 A Brief Description of Fortran 90 History
4 Fortran90 extends Fortran77 -- A summary of new features:
5 Elementwise Operations in Fortran90:
Addition of Arrays

6 Elementwise Operations in Fortran90: Array Assignment
7 Global Operations in Fortran90: Reduction
8 Example of sum reduction -- Numerical Integration
9 How to create Arrays in Fortran90
10 Completing the Integration Example
11 Array Expressions
12 Selection: Conditional Evaluation of Array Operations
13 Integration Again! Simpson's Rule
14 More General Elementwise Operations
15 More Details on Array Operations in Fortran90 ---
The Parts of a Fortran Program

16 The same program in Free Form syntax
How to declare Array Properties

17 Array Indexing
18 Array Constructors for Array Objects
19 Array Sections for Array Objects
20 Use of Subscript Triples to Specify array Sections
21 How to Specify Array Sections with Vector Valued Subscripts
22 Using Arrays in Expressions and Statements: Arrays must be same shape(conformable)
23 Sample Program Using Array Sections
24 The Where Construct
25 The Forall Construct
26 Scan (Parallel Prefix) -- Another Global Operation
27 Example Application Using Scans -- Calculation of Binomial Coefficients
28 Arguments for Procedures
29 Interface Blocks for Called Subroutines
30 Intrinsic Functions -- Optional and Keyword Arguments
31 The Elemental and Inquiry Functions
32 Array Transformation Functions
33 The Arrray Location Functions
34 Array Construction Functions
35 An Example of Use of Intrinsic Functions
36 Shift Intrinsic Transformation Functions
37 Some Simple Matrix Manipulation Intrinsic Functions
38 The Algorithm for Gauss-Jordan Matrix Inversion
39 The array operations needed before and after pivot row handled separately
40 The part of Gauss-Jordan addressing first set of rows before row i
41 The Fortran90 Gauss Jordan Program

Outside Index Summary of Material



HTML version of Basic Foils prepared 21 Sept 1995

Foil 1 Introduction to Fortran90
for CPS615 Fall 95

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Nancy McCracken
Geoffrey Fox
NPAC
Syracuse University
111 College Place
Syracuse NY 13244-4100

HTML version of Basic Foils prepared 21 Sept 1995

Foil 2 Abstract of Fortran90 Overview for CPS615

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
This introduces array notation and describes basic array operators
Array Constructors and Array Sections
The Where Construct
Forall available in some compilers and critical for parallelism
Subroutines and Interfaces
Intrinsic Functions
A simple Gauss-Jordan Matrix Inversion is used as an example

HTML version of Basic Foils prepared 21 Sept 1995

Foil 3 A Brief Description of Fortran 90 History

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Designed by X3J3 Standards committee between 1979 and 1991. The committee was part of the International Standards Organization and is also accredited by ANSI, the American National Standards Institute. In 1991, the committee had 46 members:
  • universities 5
  • user groups 6
  • international groups 7
  • government organizations 6
  • vendors 22

HTML version of Basic Foils prepared 21 Sept 1995

Foil 4 Fortran90 extends Fortran77 -- A summary of new features:

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Array operations
Pointers
Improved facilities for numerical computation including a set of numeric inquiry functions
Parameterization of the intrinsic types, to permit processors to support short integers, very large character sets, etc.
User-defined derived data types composed of arbitrary data structures and operations on those structures.
Modules, for global data definitions and procedure libraries.
Source form, more appropriate for the terminal
New control constructs, forms of CASE and DO
Recursive procedures
Optional and keyword arguments
Dynamic storage allocation
Improved 1/0facilities
Additional intrinsic procedures
Evolution of the language by labelling some features "obsolescent"

HTML version of Basic Foils prepared 21 Sept 1995

Foil 5 Elementwise Operations in Fortran90:
Addition of Arrays

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Let a and b be conformable (same shape) integer arrays
a + b creates a new array of the same shape
i.e. the same size and number of dimensions

HTML version of Basic Foils prepared 21 Sept 1995

Foil 6 Elementwise Operations in Fortran90: Array Assignment

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
b=a copies data from array a to array b

HTML version of Basic Foils prepared 21 Sept 1995

Foil 7 Global Operations in Fortran90: Reduction

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Let a be an array of integer or real numbers of any size and shape
Sum reduction(a) = S ai where sum over i runs over index set of a
Sum is the Fortran90 function for sum reduction of the entire array a

HTML version of Basic Foils prepared 21 Sept 1995

Foil 8 Example of sum reduction -- Numerical Integration

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 9 How to create Arrays in Fortran90

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
[1:N] creates an array of contiguous numbers (Standard syntax: ( i, i = 1,N ))
Creating arrays: Constants (Spread or broadening)
No special syntax is needed -- just set array of desired shape to the constant 3

HTML version of Basic Foils prepared 21 Sept 1995

Foil 10 Completing the Integration Example

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Calculate the function fval for a particular polynomial
Note in a real implementation, integrate should be made into a subroutine with fval as a parameter
Use uniform interval widths so that width is not an array but a scalar constant

HTML version of Basic Foils prepared 21 Sept 1995

Foil 11 Array Expressions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Creating a subset of a one-dimensional array
Given an array fval of length N+1, fval(2:N+1) gives an array containing last N values.
Any arrays can be used together in an expression if they are "conformable"
  • Consider Integration Example again

HTML version of Basic Foils prepared 21 Sept 1995

Foil 12 Selection: Conditional Evaluation of Array Operations

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
A Boolean array -- here called L -- can determine a "context" in which a data-parallel operation is evaluated
This example gives a final array with undefined elements and corresponds to
Fortran 90 selection statement
where L
  • a=a+b

HTML version of Basic Foils prepared 21 Sept 1995

Foil 13 Integration Again! Simpson's Rule

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 14 More General Elementwise Operations

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
One can code very general index sets for elementwise expressions using the forall statement
Note that the body of a forall statement is executed "in parallel". There is NO dependence between different forall statement indices.
This important difference from DO loops

HTML version of Basic Foils prepared 21 Sept 1995

Foil 15 More Details on Array Operations in Fortran90 ---
The Parts of a Fortran Program

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 16 The same program in Free Form syntax
How to declare Array Properties

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
A number of properties are established by this declaration:
  • The type of the elements is integer.
  • Other possible types are real, logical, char, real*4, real*8 etc.
  • The rank of the array is two (two-dimensional)
  • The extent of the first dimension (the number of elements) is N.
  • The extent of the second dimension is 9
  • If the lower bound is 1, 1:N can be abbreviated as N
  • The shape of the array is [N,9] -- a vector consisting of the extents of the dimensions.
The following Fortran77 declaration is equivalent

HTML version of Basic Foils prepared 21 Sept 1995

Foil 17 Array Indexing

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Indexing individual elements or
Array objects i.e. whole arrays

HTML version of Basic Foils prepared 21 Sept 1995

Foil 18 Array Constructors for Array Objects

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Note syntax [ and ] can be replaced by (/ and /)
Other Types of arrays can be constructed:

HTML version of Basic Foils prepared 21 Sept 1995

Foil 19 Array Sections for Array Objects

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 20 Use of Subscript Triples to Specify array Sections

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 21 How to Specify Array Sections with Vector Valued Subscripts

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
uses the values of a one-dimensional array as subscripts to another array

HTML version of Basic Foils prepared 21 Sept 1995

Foil 22 Using Arrays in Expressions and Statements: Arrays must be same shape(conformable)

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Basic Array Assignment
Assigning to one row of a two dimensional array. The remaining array values are unchanged
Restriction on array assignment
Assignment Collisions are NOT allowed!
The result is undefined and runtime errors may result

HTML version of Basic Foils prepared 21 Sept 1995

Foil 23 Sample Program Using Array Sections

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Simpson's Rule for Integration using array sections to select different weightings

HTML version of Basic Foils prepared 21 Sept 1995

Foil 24 The Where Construct

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Single Assignment where statement with conformable arrays
Multiple Assignment Where Construct

HTML version of Basic Foils prepared 21 Sept 1995

Foil 25 The Forall Construct

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Not in the Fortran90 standard language but is in HPF and many Fortran90 compilers provide it
Single Assignment Forall Statements
Forall statements where individual values depend on the index variables

HTML version of Basic Foils prepared 21 Sept 1995

Foil 26 Scan (Parallel Prefix) -- Another Global Operation

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Let a be an array of integer or real numbers of any shape.
Define the inclusive scan by:
With example:

HTML version of Basic Foils prepared 21 Sept 1995

Foil 27 Example Application Using Scans -- Calculation of Binomial Coefficients

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Calculate an array, bin, of binomial coefficients
This simple program isn't very good -- it gets arithmetic overflow except at small n
Can you formulate a better algorithm in Fortran90 ?

HTML version of Basic Foils prepared 21 Sept 1995

Foil 28 Arguments for Procedures

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
In Fortran90, each subroutine, function and (main) program are compiled independently
  • Default implies that cannot refer to variables from one procedure in another
One can pass arguments and these are passed by reference(address) not value as in Fortran77
Common blocks or modules can be used for global declaration of variables that can be referenced in all subroutines

HTML version of Basic Foils prepared 21 Sept 1995

Foil 29 Interface Blocks for Called Subroutines

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Interface blocks are used in calling procedure to allow compiler to check the syntax and argument types in subroutine calls

HTML version of Basic Foils prepared 21 Sept 1995

Foil 30 Intrinsic Functions -- Optional and Keyword Arguments

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Intrinsic functions are part of the language and not part of library. They have a function and not an operator notation
The general form of these built in functions is:
Optional arguments and keyword arguments are also allowed for user-defined functions

HTML version of Basic Foils prepared 21 Sept 1995

Foil 31 The Elemental and Inquiry Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
All standard functions of arithmetic, trigonometry and type conversion etc. are extended in a natural way to operate elementwise on arrays
Here is a teensy sample!
There are also a new set of inquiry functions in intrinsic set

HTML version of Basic Foils prepared 21 Sept 1995

Foil 32 Array Transformation Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
There are a set of reduction functions already exemplied by sum
Here is another example of sum reducing over first dimension (columns) and over second dimension(rows)

HTML version of Basic Foils prepared 21 Sept 1995

Foil 33 The Arrray Location Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
These are new for Fortran90 and find location of particular elements.
They return a vector of array indices for the location of an element.
If more than one element satisfies the criteria, as in more than one minimum or maximum element, the first such element (as defined by column major order) is returned.

HTML version of Basic Foils prepared 21 Sept 1995

Foil 34 Array Construction Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Array construction functions
Here is an example of reshaping a one dimensional array into a two dimensional form with shape 3 by 8

HTML version of Basic Foils prepared 21 Sept 1995

Foil 35 An Example of Use of Intrinsic Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 36 Shift Intrinsic Transformation Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Array shift functions and an example

HTML version of Basic Foils prepared 21 Sept 1995

Foil 37 Some Simple Matrix Manipulation Intrinsic Functions

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
Note matmul is multiplication of arrays as matrices
a * b is multiplication of corresponding elements
Libraries such as IBM ESSL or HPCC SCALAPACK give you more general matrix operations such solution of equations

HTML version of Basic Foils prepared 21 Sept 1995

Foil 38 The Algorithm for Gauss-Jordan Matrix Inversion

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 39 The array operations needed before and after pivot row handled separately

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index

HTML version of Basic Foils prepared 21 Sept 1995

Foil 40 The part of Gauss-Jordan addressing first set of rows before row i

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
For all rows j before i'th row:
A similar strategy is used for the rows after row i and between them these two processes complete row transformations for i'th column

HTML version of Basic Foils prepared 21 Sept 1995

Foil 41 The Fortran90 Gauss Jordan Program

From New CPS615 Foils-- 28 August 95 CPS615 Basic Simulation Track for Computational Science -- Fall Semester 95. *
Full HTML Index
This is a simplified code which only works for "nice" matrices where you do not need to check for zero's on the diagonal and use pivoting for robust results

© on Tue Oct 7 1997