Using Fortran, early and accurate forecasts for hurricanes and other major storms have saved thousands of lives.
A novel and interesting approach to learning both Fortran and concurrent programming in general.
Using Fortran, better designs for ships, planes, and automobiles have made travel safer, more efficient, and less expensive than ever before.
Using Fortran, low-level machine learning and deep learning libraries provide incredibly easy, fast, and insightful analysis of massive data for science, business, and industry.
Fortran is an amazingly powerful and flexible programming language that forms the foundation of high performance computing for research, science, and industry. And it's come a long, long way since starting life on IBM mainframes in 1956. Modern Fortran is natively parallel, so it's uniquely suited for efficiently handling problems like complex simulations, long-range predictions, and ultra-precise designs. If you're working on tasks where speed, accuracy, and efficiency matter, it's time to discover—or re-discover—Fortran.
Part 1: Getting started with modern Fortran
1. Introducing Fortran
1.1. What is Fortran?
1.2. Fortran features
1.3. Why learn Fortran?
1.4. Advantages and disadvantages
1.4.1. Side-by-side comparison with Python
1.5. The parallel Fortran mental model
1.6. What will you learn in this book?
1.7. Think parallel!
1.7.1. Copying an array from one processor to another
1.8. A Partitioned Global Address Space language
1.9. Running example: A parallel tsunami simulator
1.9.1. Why tsunami simulator?
1.9.2. Shallow water equations
1.9.3. What we want our app to do
2. Getting started: Minimal working app
2.1. Compiling and running your first program
2.2. A minimal working app: Moving a blob in space
2.2.1. What should our app do?
2.2.2. What is advection?
2.2.3. Implementation strategy
2.2.4. Defining the main program unit
2.2.5. Declaring and initializing variables
2.2.6. Numeric data types
2.2.7. Declaring variables
2.2.8. Declaring constants
2.2.9. Declaring arrays
2.2.10. Portable data types with
2.2.11. Using a
do-loop to iterate
2.2.12. Setting initial conditions for the blob
2.2.13. Predicting the movement of the blob
2.2.14. Writing to screen
2.2.15. Putting it all together
2.3. Going forward
3. Writing reusable code with procedures and modules
3.1. Toward higher app complexity
3.1.1. Adding terms to the tsunami simulator
3.2. An overview of Fortran program units
3.3. Revisiting the cold front problem
3.4. Don’t repeat yourself, use procedures!
3.5. Using pure procedures to avoid side effects
3.5.1. What is a pure procedure?
3.5.2. Some restrictions on pure procedures
3.5.3. Why are pure functions important?
3.6. Writing procedures that operate on both scalars and arrays
3.7. Storing globally accessible data and procedures in modules
3.7.1. Defining a module
3.7.2. Accessing procedures and variables in a module
3.7.3. Controlling the visibility and access to variables and procedures
3.8. Incorporating modules and procedures in the Tsunami app
3.8.1. Refactoring the minimal working app with modules and functions
3.8.2. Toward realistic wave simulations
3.9. Answer key
3.9.1. Exercise 1: Calculating the temperature due to cold front passage
3.9.2. Exercise 2: Cold front solution using an external function.
3.9.3. Exercise 3: Modifying state with a subroutine
3.9.4. Exercise 4: Writing an elemental function that operates on both scalars and arrays
4. Analyzing time series data with arrays
4.1. Analyzing stock prices with Fortran arrays
4.1.1. Objectives for this exercise
4.1.2. About the data
4.1.3. Getting the data and code
4.2. Finding the best and worst performing stocks
4.2.1. Declaring arrays
4.2.2. Array constructors
4.2.3. Reading stock data from files
4.2.4. Allocating arrays of certain size or range
4.2.5. Allocating array from another array
4.2.6. Cleaning up after use
4.2.7. Checking for allocation status
4.2.8. Catching allocation and deallocation errors
4.2.9. Implementing the CSV reader subroutine
4.2.10. Indexing and slicing arrays
4.3. Identifying risky stocks
4.4. Finding good times to buy and sell
4.5. Answer Key
4.5.1. Exercise 1: Convenience (de)allocator subroutines
4.5.2. Exercise 2: Reversing an array
4.5.3. Exercise 3: Computing the moving average over custom time period.
Part 2: Advanced Fortran use
5. Going parallel with Fortran coarrays
5.1. Why write parallel programs
5.2. Processing real-world weather buoy data
5.2.1. About the data
5.2.2. Getting the data and code
5.2.4. Serial implementation of the program
5.3. Parallel processing with images and coarrays
5.3.1. Fortran images
5.3.2. Getting information about the images
5.3.3. Telling images what to do
5.3.4. Gathering all data to a single image
5.4. Coarrays and synchronization, explained
5.4.1. Declaring coarrays
5.4.2. Allocating dynamic coarrays
5.4.3. Sending and receiving data
5.4.4. Controlling the order of image execution
5.5. Toward the parallel Tsunami simulator
5.5.1. Implementation strategy
5.5.2. Finding the indices of neighbor images
5.5.3. Allocating the coarrays
5.5.4. The main time loop
5.6. Answer key
5.6.1. Exercise 1: Finding the array sub-ranges on each image.
5.6.2. Exercise 2: Writing a function that returns the indices of neighbor images
6. Using derived types to work withabstract data
7. Overloading operators and generic functions
8. Input and output: Namelists, JSON, and NetCDF
Part 3: The final stretch
9. Advanced parallelism with teams and events
10. Interoperability with C: Exposing your app to the web
11. Easy to use apps with rich CLIs and documentation
12. Publishing your Fortran app
Appendix A: Setting up the Fortran development environment
A.1. Editing Fortran source files
A.2. Setting up the compiler and libraries
A.2.1. Setting up the Fortran compiler
A.2.2. Setting up the MPI library
A.2.3. Setting up OpenCoarrays
Appendix B: From calculus to code
B.1. The advection equation explained
B.1.1. Discretizing the derivatives
B.1.2. Casting the derivatives into code
Appendix C: Glossary
About the TechnologyFortran is a general-purpose programming language that is dominant in engineering and scientific computing applications. It's the leading language used in high performance (HPC) and parallel programming. While Fortran is the oldest high-level programming language, it is constantly improving. The most recent major revision of the standard, Fortran 2008, added native support for parallel programming on shared-and distributed-memory architectures, and will be one of few languages used for next-generation exascale HPC applications. Fortran 2018 will include additional parallel features and improve interoperability with C.
A few Fortran facts:
- If you read or listened to the weather forecast this morning, you used Fortran.
- You'll find Fortran at the lowest levels of most popular data analysis and machine learning frameworks.
- Fortran is the reference benchmark language used to measure the performance of the fastest supercomputers in the world (https://top500.org)
- Fortran is the only natively-parallel programming language steered by an International Standards Committee with scientists and engineers as its target audience.
- Fortran is the dominant language of the High Performance Computing, spanning industries from applied mathematics, fluid and aerodynamics, to weather, ocean, and climate prediction.
Simply put, the future is in parallel, and Fortran is already there.
About the bookModern Fortran: Building Efficient Parallel Applications teaches you how to develop fast, efficient parallel applications with Fortran. To warm up, you'll start by building a simple application in modern Fortran, with a focus on reusable modules, functions, and subroutines. Next, you'll dive into Fortran's unique approach to parallel programming with coarrays. As you work through this practical guide, you'll systematically explore all the really interesting stuff: how to overload operators and generic functions, work with a variety of different inputs and outputs, and much more. Finally, you'll take on advanced parallelism with teams and events, interoperability with C, and even publishing your finished app.
Packed with practical examples, tasks to practice, cookbook-style recipes, Modern Fortran is guaranteed to make you see this powerful language in a new light.
- Fortran's place in the modern world
- Parallel programming from the ground up
- Working with variables and types
- Module development in Fortran
- Interfacing Fortran with C, C++, and Python
- Object-oriented and functional programming styles
About the readerWritten for developers, engineers, and computational scientists. No prior experience with Fortran in needed.
About the authorMilan Curcic is a meteorologist and oceanographer. A Fortran programmer since 2006, he has worked with teams from United States Navy and NASA on developing and improving Earth system prediction models. Milan has authored two general-purpose Fortran libraries and is currently working on a startup porting Fortran to the cloud for weather and ocean prediction.
Great book for beginners in Fortran.
A great way to familiarize yourself with Fortran. You'll feel as if you were a scientist, solving real-world numerical problems using simulations.