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 |
Outside Index Summary of Material
Nancy McCracken |
Geoffrey Fox |
NPAC |
Syracuse University |
111 College Place |
Syracuse NY 13244-4100 |
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 |
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:
|
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" |
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 |
b=a copies data from array a to array b |
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 |
[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 |
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 |
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"
|
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
|
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 |
A number of properties are established by this declaration:
|
The following Fortran77 declaration is equivalent |
Indexing individual elements or |
Array objects i.e. whole arrays |
Note syntax [ and ] can be replaced by (/ and /) |
Other Types of arrays can be constructed: |
uses the values of a one-dimensional array as subscripts to another array |
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 |
Simpson's Rule for Integration using array sections to select different weightings |
Single Assignment where statement with conformable arrays |
Multiple Assignment Where Construct |
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 |
Let a be an array of integer or real numbers of any shape. |
Define the inclusive scan by: |
With example: |
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 ? |
In Fortran90, each subroutine, function and (main) program are compiled independently
|
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 |
Interface blocks are used in calling procedure to allow compiler to check the syntax and argument types in subroutine calls |
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 |
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 |
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) |
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. |
Array construction functions |
Here is an example of reshaping a one dimensional array into a two dimensional form with shape 3 by 8 |
Array shift functions and an example |
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 |
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 |
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 |