The Queen's University of Belfast

Parallel Computer Centre
[Next] [Previous] [Top]
1 Introduction
1.1 Programming in general
A program is the tool a user employs to exploit the power of the computer. A program is written in a language which is understood by the computer hardware. A program consists of a sequence of steps which when executed result in a task being carried out. Execution means that the computer is able to interpret each step (instruction), interpretation refers to understanding what is required and instructing the hardware to carry it out. Each instruction might require a calculation to be performed, or a decision to be selected, or some information to be stored or retrieved. The nature of the instruction depends on what programming language is used. Each programming language has its own set of statements.
1.1.1 Available programming languages
There are hundreds of programming languages. A general txonomy of the available programming languages is given below.
- Machine codes use strings of 0s and 1s to express instructions and they dependent on the underlying hardware.
- Assembly languages are also dependent on hardware and utilise a symbolic form to express instructions.
- High level languages were developed to ease the programming effort and to provide hardware independence. Despite that they are multi-purpose languages they have different strengths. For example, Fortran is popular with the scientific and engineering community, Cobol is used for business applications and C for systems programming.
- Logic programming involves the construction of a database with facts and rules and the program examines the database to locate one or more rule that apply with a given input.
- Functional programming involves the construction of functions. A function is written using normal mathematical principles and the computer evaluates the function and prints the result(s).
- Simulation languages are used to model activities of discrete systems (traffic flow) and are used to predict the behaviour (traffic jams) of the system by asking hypothetical questions (traffic density increase)
- String manipulation languages perform pattern matching where strings of characters are compared.
- Object-oriented languages such as Smalltalk provide programming environments by integrating the language with support tools. Languages such as C++ encourage the decomposition of a problem into smaller sub-problems by allowing encapsulation, polymorphism and inheritance.
- 4GLs remove the need for a user to write programs from scratch by using pre-programmed forms.
1.1.2 Choosing a programming language
The choice of what language to employ depends on two factors:
- Practical considerations - these include cost consideration (a company might have already invested a lot of money in a particular language by purchasing appropriate compilers/hardware. Existing Fortran programs easier to change to 90 rather than to C); application consideration (Fortran is the language for number crunching but would not use for database development); expertise consideration (cost for re-training staff in a new language).
- Language considerations: In general one desires a language with a notation that fits the problem, simple to write and learn, powerful operations etc. Fortran is superior to other languages for numerical computation, many diverse and reliable libraries of routines are available, an official standard exists which helps towards portability.
1.2 History
Fortran (mathematical FORmula TRANslation system) was originally developed in 1954 by IBM. Fortran was one the first to allow the programmer to use a higher level language rather than machine code (0s and 1s) or assembly language (using mnemonics). This resulted in programs being easier to read, understand and debug and saved the programmer from having to work with the details of the underlying computer architecture.
In 1958 the second version was released with a number of additions (subroutines, functions, common blocks). A number of other companies then started developing their own versions of compilers (programs which translate the high level commands to machine code) to deal with the problem of portability (machine dependency).
In 1962 Fortran IV was released. This attempted to standardize the language in order to work independent of the computer (as long as the Fortran IV compiler was available!)
In 1966 the first ANSI (American National Standards Institute) standard was released which defined a solid base for further development of the language.
In 1978 the second ANSI standard was released which standardized extensions, allowed structured programming, and introduced new features for the IF construct and the character data type.
The third ANSI standard was released in 1991, with a new revision expected within 10 years.
1.3 ANSI Standard
Fortran 90 is a superset of Fortran 77. New facilities for array type operations, new methods for specifying precision, free form, recursion, dynamic arrays etc. were introduced. Despite that the whole Fortran77 is included the new ANSI standard proposes that some of the Fortran77 features are obsolete and will be removed in the next version.
In theory a Fortran 77 program should compile successfully with a Fortran 90 compiler with minor changes. This is the last time a reference to Fortran 77 is made and it is recommended that programmers new to Fortran not to consult any Fortran 77 books.
The Fortran 90 version was augmented with a number of new features because previously modern developments were not accommodated. Developments such as the recent importance of dynamic data structures and the (re)introduction of parallel architecture.
Comparing with other languages, and only for number crunching, one can see that Fortran90 scores higher on numeric polymorphism, decimal precision selection, real Kind type etc. Only 90 has data parallel capabilities meaningful for numeric computation which are missing from other languages. Also 90's data abstraction is not as powerful as in C++ but it avoids the complexities of object-oriented programming.
1.4 The Program - Planning
Writing a program is not a floating task. Previous to code writing one has to go through certain stages:
- Analyse and specify requirements.
- Design the solution.
- Code the solution using the chosen programming language.
At the end of coding, verification, testing and maintenance are also required.
The stages are iterative and the sooner errors are found the better. These stages though are not discussed in this course but the interested reader can consult any software book for more information. Here, the concentration lies with coding with a brief introduction to design using algorithms.
1.5 The Program - Algorithms
The design phase is one of the most important and usually difficult stage. One tool used to design the program is the algorithm. With an algorithm the steps required to carry out a given task are clearly described. The algorithm will include instructions for how to:
- accept information
- display information
- transformations
- how to select decisions
- how to repeat sub-tasks
- when to terminate
Writing musical score is an algorithm where the notes express tasks. For programming though an algorithm is expressed using English-like instructions. An algorithm is independent of the programming language or the computer hardware to be used, but influenced. A programming language acts like a convenient medium for expressing algorithm and the computer is simply the medium of execution. The solution process expressed as an algorithm can not obviously be executed since computers do not handle well the idiosyncrasies of a natural language or subset of it (but moving towards it)
1.6 The Program - Example of an algorithm
Consider the following algorithm;
- Get a number
- Save the number
- Get a new number
- While there is a new number
- If the new number is greater than that saved
Save the new number
end if
- Get a new number
end while
- Print saved number
This is a proposed solution for finding and displaying the greatest number from a given list of numbers. The input terminates when the user enters the blank character.
Notice the English-like expressions. Obviously, one can use Read or Input instead of Get; or store instead of save; or '>' instead of greater than. Notice also the numbering system. This helps towards stepwise refinement. For example, if statement X needed more clarification then the new statements take the value X.1 to X.n. This makes referencing statements easier.
Notice the indentation and the end-if and end-while which make clear where a comparison / loop terminates.
1.7 The minimum program
Consider the following program
PROGRAM nothing
! does nothing
END PROGRAM nothing
This is probably the simplest Fortran90 program. It does nothing. The first statement simply tells the compiler that a program named nothing is to follow. The second statement is a comment (because of the exclamation mark) and it is ignored by the compiler. The third and last statement informs the compiler that the program terminates at that point. Notice that statements between PROGRAM and END are executed in the order that they are written (not strictly true but ok for the moment). Keywords such as PROGRAM and END are written in capitals just for illustration purposes. Small case or a mixture of upper and lower case is acceptable. So PROGRAM, Program, PROgrAM are all acceptable.
Consider the following (more complicated) program
PROGRAM hi
! display a message
WRITE(*,*) 'Hello World!'
END PROGRAM hi
The above program introduces the concept of displaying information to the screen (or other devices). Running this program the message Hello World (without the quotes) will appear on the screen. This is achieved by employing the keyword WRITE and typing the appropriate message between single quotes. One can extend the program to, say, display the name of the current user. Then using in a similar fashion another available keyword (READ) the user can enter his/her name and by changing the WRITE statement he/she can display the name.
1.8 Compilation
Once the program has been designed and entered into a file then the following steps are followed:
- Compilation step: This is initiated by the programmer, by typing:
f90 filename.f90
its purpose is to translate the high-level statements into machine code. The compiler checks the syntax of the statements against the standard (write rather than write will give an error) and the semantics of the statements (referencing a variable with no declaration). This step generates the object code version which is stored in a file of the same name but different extension.
- Linking step: This might be initiated by the compiler and its purpose is to insert code for a referenced operation from the library. This generates the executable code version which again is stored in a file with a different extension.
- Execution step: This is initiated by the programmer/user, by typing a.out, and its purpose is to run the program to get some answers. During execution the program might crash if it comes across an execution error (most common execution error is the attempt to divide by zero).
Notice that logical errors (multiply rather than add) can not be checked by the compiler and it is the responsibility of the designer to identify and eliminate such errors. One way to do so is by testing against data with known results but for more complex programs testing can not take into consideration all possible combinations of inputs therefore great care must be taken during the initial design. Identifying errors at the design phase is cheaper and easier.
[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker