next up previous
Next: About this document ...

Worksheet 1 - PHY201, Fall 2006
Due Friday Sept. 8th, 5pm
Physics 201 home

FORTRAN (FORmula TRANslation) remains the workhorse of scientific computing. The majority of existing codes for scientific simulation are in fortran, many still in the old Fortran 77 standard. Fortran 90 contains many important improvements over Fortran 77. Fortran is a continuously evolving language, and a great deal of "backward compatability" is maintained. Only the most odeous of old constructs are explicitly removed in the recent versions of Fortran.

Here is a brief history of Fortran: 1954, Fortran I; 1958, Fortran II; 1958, Fortran IV; 1966, Fortran 66 standard; 1978, Fortran 77 standard; 1991, Fortran 90(and HP) standard; 1996, Fortran 95 standard; 2001, Fortran 2003. You need to understand the main features of Fortran 77 through Fortran 95, as in looking at existing codes, you will find a variety of different constructs drawn from these standards. We will concentrate on the Fortran 90 standard but we will also go over some of the F77 and F95 structures. HPF is a superset of Fortran 90 and is designed to take advantage of parallel computing architectures. The first thing to do however is to learn Fortan 90, which provides many of the contstructs which modern compilers can automatically optimize for parallel platforms.

Although Fortran is often criticized and is sometimes referred to as the "programming language of the past" it is, and most likely will continue to be, the a popular language for large-scale scientific computing. The ``Object-Oriented-Programming'' (OOP) revolution (e.g. C++ and more recently Java) have not superceded Fortran, as the modern Fortran standards incorporate many of the most useful features of OOP. OOP attempts to enable maximum transferability of code, so that in C++, subunits are placed in "CLASSES" which can be included in a variety of larger programming units. In the Fortran 77 standard FUNCTIONS and SUBROUTINES do some of this, but their transferability is limited. Fortran has responded by introducing MODULES which do provide many of the features of CLASSES. You should also note that the performance of C++ and Java in large scale computing is also continuously improving as the compilers for these programming languages are being optimized for scientific computing.

There are literally hundreds of different computing languages, so that no-one knows them all. People tend to have a religous attachment to the language with which they are most familiar, leading to vacuous conflicts between opposing religious factions. Object oriented programming (OOP) discussions also tend to get heated and strewn with imprecise pontificating taking inordinate amounts of time. Nevertheless program design is very important. The larger the software project, and the more diverse the user community, the more important the design. Portability is also a major factor requiring considerable programming sophistication. Before worrying about these sophistications, we will go through some reasonably sophisticated computational tasks, by developing code that does not comply with OOP and is not portable in the most rigorous sense.

Though the above list of programming languages seems overwhelming at first, learning a new programming language in not a difficult task, once you have learned one of them well. In fact Mathematica is in many ways a programming language and many of the contructs used there appear in Fortran and/or C,C++. In general Mathematica is less efficient for large-scale calculations, but it is very convenient and useful for smaller scale calculations and for checking your large scale FORTRAN codes. Another useful general purpose package is Matlab which is becoming more efficient at large scale numerical simulations.

For the first worksheet

Read pages 6-15 of the summary of Fortran 90. Here are two examples which you can use as templates for this week's problems.

- 1. sample file 1 which prints out my name and ambition.

- 2. sample file 2 which squares the SIN of an integer and sums that over the first 100 integers.

PROBLEMS

- 1. Write a Fortran program which inputs two integers from the screen. Then do the following to the two integers: Sum them, subtract them, multiply them and divide them. Then print out the two integers along with the results of the above operations. Make sure you also print out some text so you know what each output number means. Also print out a prompt so you know what to input.

- 2. Write a Fortran code which calculates and prints out the sum of 1/k^2 for three cases: Where k runs over the first 3 positive integers; where k runs over the first 10 positive integers; where k runs over the first 100 positive integers. Check your answers by doing the same sums using Mathematica - also hand in the Mathematica code.

Linux commands you need to know

- (i) yppasswd - change your password (and remember it!!!)

- (ii) emacs - Use this to edit files.

- (iii) f90-vast - Use this to compile your fortran program

e.g. f90-vast -o test.exe test.f90
This generates the executable and writes it onto test.exe. If you do not specify a destination file e.g. using only: f90-vast test.f90 The executable is written onto the file a.out.

- (iv) How to run an executable - Type ./test.exe (or ./a.out)

- (v) Another compiler you should know about is g77. This is a Fortran 77 compiler than comes with the Linux distribution. However it understands quite a few of the basic Fortran 90 instructions though it does not handle the more sophisticated aspects of fortran 90.



 
next up previous
Next: About this document ...
Phil Duxbury
2001-08-27