Summary and Schedule
Description
This course is aimed at users and developers who know how to program, but have little or no experience in Fortran, and those who may wish to have a refresher in Fortran.
Fortran (a contraction of Formula Translation) was the first programming language to have a standard (in 1954), but has changed significantly over the years. More recent standards (the latest being Fortran 2023) come under the umbrella term “Modern Fortran”. Fortran retains very great significance in many areas of scientific and numerical computing, particularly for applications such as quantum chemistry, plasmas, and in numerical weather prediction and climate models.
This course provides an introduction to the basics of writing Fortran. It will cover basic syntax, variables, expressions and assignments, flow of control, and introductions to I/O and user-defined types. Common Fortran idioms are introduced and contrasted with those available in C-like languages; the course will try to focus on real usage rather than formal descriptions.
At the end of the course you should be able to understand many Fortran programs and be confident enough to start writing well-structured and portable Fortran. Fortran is a rather “large” language, so it is not possible to cover all its features in a three day course. Further elements of Fortran are discussed in the “Intermediate Modern Fortran” course.
The course requires a Fortran compiler. We will provide accounts on ARCHER2 for you to use; this guarantees that everyone is working in the same environment with the same software. That said, if you wish to work on a local machine or laptop which has a Fortran compiler [1], you of course may do so. Use of a text editor will be required will be required.
[1] This may typically be gfortran, freely available as
part of GNU Compiler Collection (GCC). See e.g., https://gcc.gnu.org/wiki/GFortranBinaries.
General Information
Requirements: Participants must have a working laptop or desktop computer with a Mac, Linux, or Windows operating system (not a tablet, Chromebook, etc.) that they have administrative privileges on. They should have access to a terminal (Mac and Linux users should have a terminal installed by default; Windows users should get either MobaXterm or PuTTY. They are also required to abide by the ARCHER2 Training Code of Conduct.
You should have used remote HPC facilities before. In particular, you
should be happy with connecting using SSH, know what a batch scheduling
system is and be familiar with using the Linux command line. You should
also be happy editing plain text files in a remote terminal (or,
alternatively, editing them on your local system and copying them to the
remote HPC system using scp).
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m | 1. Connecting to ARCHER2 and transferring data |
What can I expect from this course? How will the course work and how will I get help? How can I give feedback to improve the course? How can I access ARCHER2 interactively? |
| Duration: 00h 40m | 2. Hello World |
What is the structure of a Fortran program? How do I print output from the program to the terminal? |
| Duration: 01h 00m | 3. Break | |
| Duration: 01h 40m | 4. Variables |
What are some basic types of numeric variables in Fortran? How are variables declared and defined? How do I create constants? |
| Duration: 02h 10m | 5. Logical and conditionals, character variables |
What other types of variable does Fortran provide? How can I direct a program’s flow down different paths? Is it possible to store characters in a variable? |
| Duration: 02h 30m | 6. Lunch | |
| Duration: 03h 40m | 7. Loops and loop control |
How can I make the program do work repeatedly? How can I have the program only do as much work as is required? |
| Duration: 04h 00m | 8. Array declarations |
How do I create arrays of different sizes and numbers of
dimensions? Can I create the arrays at runtime if I don’t yet know how big they need to be? |
| Duration: 04h 20m | 9. Array expressions and assignments |
How do I assign values to Fortran arrays? Can I work at once with subsets of an array? How can I reduce or extract information from an array? |
| Duration: 04h 50m | 10. Break | |
| Duration: 05h 30m | 11. Mini exercise: a choice of two | What are some real problems I can try out? |
| Duration: 06h 30m | 12. Modules and compilation of modules |
How can I collect parameters and sub-programs of my own in a
module? Can I keep some parts of the module internal to it and hidden? Am I able to use scoping to introduce temporary variables in a larger program unit? |
| Duration: 06h 50m | 13. Functions and subroutines |
How can I factor code out into different program procedures? How do I control the flow of information into and out of procedures? |
| Duration: 07h 10m | 14. More on array dummy arguments |
What do I need to take into consideration when passing an array as an
argument? Can I pass arrays which haven’t yet been allocated? How do I implement optional dummy arguments? |
| Duration: 07h 30m | 15. Break | |
| Duration: 08h 10m | 16. More on characters and strings |
How are character variables compared in Fortran? How can I create and use flexible strings? |
| Duration: 08h 30m | 17. Formats and edit descriptors |
How do I read input from the keyboard to my program? How can I control the format of input and output of various types? |
| Duration: 08h 50m | 18. Lunch | |
| Duration: 10h 00m | 19. Operations on external files |
How do I open and close files for input and output? How do I handle any errors that might occur during I/O? |
| Duration: 10h 40m | 20. Using namelists |
What is a namelist? How can I use a namelist to read and write grouped data? |
| Duration: 11h 20m | 21. Break | |
| Duration: 12h 00m | 22. Exercises | What are some problems I can work on? |
| Duration: 13h 00m | 23. Structures: derived types |
How can I group together variables to make more complex
structures? How are these derived types defined and then initialised? |
| Duration: 13h 25m | 24. Pointers and targets |
How do I use a pointer to reference another variable? Can I alias variable names? Can I change the sizes of allocatable arrays? |
| Duration: 13h 45m | 25. Procedures again: interfaces |
What is an interface and why might I need to write one? Can I use a function or a subroutine as an argument to another procedure? How can I write a procedure that will accept arguments of different types? Can I overload arithmetic and relational operators to work with my derived types? Can I write a function that will accept both scalar and array arguments? |
| Duration: 14h 25m | 26. Break | |
| Duration: 15h 05m | 27. Miscellaneous |
How can I retrieve any command line arguments I want to give my
program? How can I examine environment variables? Can I have my Fortran code execute OS commands on the terminal? Can I get the time and date? |
| Duration: 15h 25m | 28. Lunch | |
| Duration: 16h 35m | 29. Other things you may see | What have we not covered that I should be aware of? |
| Duration: 16h 50m | 30. Exercises: conjugate gradient and matrices | How can I really push what I’ve learnt so far? |
| Duration: 17h 50m | 31. Break | |
| Duration: 18h 30m | 32. Exercises | |
| Duration: 19h 35m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Please try to complete the following setup tasks ahead of the lesson.
Create appropriate SAFE and ARCHER2 machine accounts
Course attendees should have received instructions on how to set up an ARCHER2 SAFE account. Details are available in the ARCHER2 documentation.
You will firstly create a SAFE account. The SAFE is used to manage ARCHER2 projects and accounts. Once you have a SAFE account, you will then be able to request an account on ARCHER2 itself. (If you already have a SAFE or ARCHER2 machine account, you may reuse those.)
Any problems encountered will be addressed as the first part of the course.