Simulation
course
FYSM350
7.2.-16.5.2006
Fortran 90/95/2003
Tuesdays
lecture: 12.15-14.00 in MaD202
Thursdays lecture 12.15-14.00 in
Fys2
Language: english
Lecturer: Vesa
Apaja email: firstname.lastname@gmail.com
Synopsis: The goal is to learn to write
simulation routines in Fortran – the number crunchers, not the
GUI's.
After
introduction to the basic properties of the language we will also
examine a few real simulation codes:
how they work, why certain
choices have been made etc.
Some object oriented features
are introduced, paying attention to good programming habits
and
how to write programs that run fast.
Grading: passed or not
Requirements:
Attend the lectures (about 60% of them: for special reasons some special arrangements are possible)
Document your work using a LEARNING
DIARY (OPPIMISPÄIVÄKIRJA)
-
work hours, when and how you used them: a couple of sentences
about each two hours
- what have you learned and what more
should you learn about each subject
Do the two programming tasks (to be given later)
Recommended:
If you have a computer, install a f90 (f95) compiler
Some free compilers for Intel/AMD platforms: Intel fortran-95 compiler (Linux) gnu fortran-95 compiler (Linux or Windows)
Check out the screenshot of the gnu fortran (g95) compiler :^)
Unfortunately Intel compiler for Windows is only an evaluation copy (licensed till March). But you can use g95 in Windows as well.
Course material (pdf format) : HERE
HOMEWORK I
HOMEWORK II Your Boss has written a few f90 programs late last night.
They have mistakes - as usual - and now the Boss wants you to fix them.
Some mistakes are just typos, but some are more subtle.
You are not allowed to rewrite the programs from scratch – your Boss would not like to see last nights work thrown away and you want to get paid also next year.
Fix the following programs: Send the working versions to Vesa along with comment lines that describe what was wrong and why it was wrong.
Broken 0 "This one contains only simple mistakes."
Broken 1 "This seemed to be such a simple task, I don't know why it gives these strange numbers."
This one is voluntary, except for those who didn't attend 60% of the lectures:
Broken 2 : "Pointers! I think there is something wrong with my random integers, too."
GENERAL INSTRUCTIONS FOR DEBUGGING:
Read only the first few compiler error messages. Every other complaint may be caused by them.
Insert temporary print statements to the program to see what values a variable gets.
Using “print” is less sophisticated than using a debugger,
but it's a method that you always have at hand. And debuggers have bugs, too.
If a complicated task doesn't work try to do a simplified version.
Some mistakes cause trouble only very rarely and may be difficult to spot.
If you you use random numbers always check carefully what happens if the random number is 0 or 1.
First of all, you should know if 0 or 1 can come out from your random number generator.
A typical problem is to have random numbers between [0,1], and you compute a random index i
of a table tab(1:n) using
i = 1+int(n*rand)
if rand happens to be exactly 1 you get i = n+1.
This means i is mostly between [1,n], but there is a tiny chance that you get i=n+1 and an oveflow in table tab.
Sample programs: Programs marked with * describe frequently used features
GET ALL SAMPLES LISTED BELOW: Tarred and gzipped or Zipped
* Basic data types and the unique behaviour of intrinsic function cmplx
* Simple subroutine
* Storage order of array element in memory
* Sending a function to a subroutine as an argument
* Array inquiry 1 : lbound, ubound and size
* Save attribute and allocatable arrays
Assumed size arrays
Assumed shape arrays and use of an interface
Array inquiry 2: behaviour with assumed shape arrays
Use of make and Makefile (expand make_example.tar in a directory)
* More simple reading of data
Reading and writing of binary data
* Namelist: reading of named parameters
* Example of the namelist input file
* matrix manipulation using builtin functions
Test for matmul speed vs. manual multiplication
Self-defined data types
Computing with self-defined data types: overloading operator "+"
* Preprocessor example
FORALL structure
* SELECT CASE structure
How to "use" only designated parts of a module
Scope of variables 1: What variables does an “external” subroutine see?
Scope of variables 2: What variables does a "contained" subroutine see?
LAPACK95 example: Solution of the hydrogen Schrödinger equation in matrix form
Mandelbrot set: complex arithmetics is simple
External
material:
CSC
(Finland) web page about f90/f95
Fortran
90 intrinsic functions
Mersenne
Twister random number generator homepage
Mersenne_Twister.f90
(f95 version of the original
C code) provides module mt95
Last modified 18.03.2006 (VA)