From Fundamentals to High-Performance Scientific Computing
Introduction
- What You Will Learn
- How to Use This Book
- A Note on Standards and Compilers
- Why Learn Fortran Today?
Chapter 1: The Story of Fortran — History, Evolution, and Modern Relevance
- The First Programming Language — FORTRAN I and the Birth of Compilers
- Standardization and Survival — From FORTRAN 66 to Fortran 90
- The Modern Renaissance — Object-Oriented Features, Parallelism, and Beyond
- Why Fortran Today — Supercomputers, Legacy Codebases, and New Projects
- How This Book Is Organized — A Roadmap for the Reader
Chapter 2: Your First Fortran Programs — Structure, Compilation, Execution
- The Anatomy of a Fortran Program — Source Files and Program Units
- Setting Up Your Environment — Compilers and Tools
- Hello World and Beyond — Free-Form Source and Basic Structure
- Compilation and Linking — From Source to Executable
- Common First Errors and How to Fix Them
- A Slightly Larger Example — Organizing Code from the Start
Chapter 3: Data, Types, and Numbers — Variables, Kinds, Precision, Literals
- Declaring Variables — Types, Names, and Style
- The Intrinsic Data Types — Integer, Real, Complex, Logical, Character
- Kinds and Numerical Precision — Choosing the Right Representation
- Literals, Constants, and Parameters — Exact Values in Code
- Operators and Expressions — Arithmetic, Relational, Logical
- Summary
Chapter 4: Control Flow and Iteration
- Conditional Execution — IF Constructs and SELECT CASE
- Looping with DO — Count-Controlled Repetition
- Advanced Loop Patterns — WHILE-like Loops, Exit, Cycle, Nested Loops
- Structured Programming Discipline — Avoiding GOTO
- Algorithmic Examples — Search, Sort, and Iterative Methods
- Summary
Chapter 5: Arrays and Array Operations
- Declaring Arrays — Shape, Bounds, and Initialization
- Multidimensional Arrays — Matrices and Beyond
- Array Syntax and Whole-Array Operations — Vectorized Code
- Slices, Sections, and Masked Arrays — Selective Access
- Memory Layout and Performance — Column-Major Order and Cache Behavior
- Summary
Chapter 6: Input and Output
- List-Directed I/O — Simple Reading and Writing
- Formatted I/O — Edit Descriptors and Precision Control
- Internal Files — String Formatting and Parsing
- Unformatted and Stream I/O — Binary Data and Portability
- Robust Input Handling — Error Checking and User Interaction
- Summary
Chapter 7: Procedures and Interfaces
- Functions and Subroutines — Designing Reusable Procedures
- Argument Passing and Intent Attributes — Clarity and Safety
- Optional and Keyword Arguments — Flexible Interfaces
- Explicit Interfaces and Interface Blocks — Compile-Time Checking
- Generic Interfaces and Operator Overloading — Polymorphic Names
- Summary
Chapter 8: Modules and Program Organization
- What Modules Are For — Encapsulation and Code Sharing
- Module Structure — Public, Private, and USE Associations
- Submodules — Separating Interface from Implementation
- Scope Rules and Name Resolution — Avoiding Collisions
- Organizing Large Projects — Module Architecture Patterns
Chapter 9: Derived Types and Object-Oriented Fortran
- Defining Derived Types — Structuring Complex Data
- Type-Bound Procedures — Methods in Fortran
- Polymorphism and the CLASS Keyword — Dynamic Dispatch
- Abstract Types and Type Extension — Inheritance Hierarchies
- Design Patterns with Modern Types — When OOP Helps
- Summary
Chapter 10: Memory Management — Allocatables, Pointers, and Dynamic Data
- Allocatable Variables — Dynamic Sizing and Lifecycle
- Allocation Patterns — Arrays, Derived Types, and Error Handling
- Pointers and Pointer Semantics — When They Make Sense
- Common Memory Pitfalls — Leaks, Dangling References, Double Free
- Modern Alternatives — Preferring Allocatables Over Pointers
Chapter 11: Parallel Programming with Coarrays
- The Coarray Model — Images, Teams, and Shared Variables
- Declaring and Using Coarrays — Basic Syntax
- Synchronization — Event-Based Coordination with SYNC
- Communication Patterns — Scatter, Gather, Reductions
- Practical Parallel Programs — Real Examples and Pitfalls
Chapter 12: Interoperability — Connecting Fortran to the World
- Why Interoperate — Ecosystems and Libraries
- The ISO_C_BINDING Module — Types, Constants, and Procedures
- Calling C from Fortran — Practical Examples
- Calling Fortran from C — Exporting Interfaces
- Beyond C — Python, Julia, and Other Language Bridges
- Summary
Chapter 13: Numerical Correctness and IEEE Floating-Point Facilities
- How Floating-Point Works — Representation and Limitations
- Precision Selection and Kind Parameters — Getting It Right
- IEEE Arithmetic Facilities — Querying and Controlling Behavior
- Numerical Stability — Algorithms That Work in Practice
- Reproducibility — Making Results Repeatable
- Summary
Chapter 14: Performance Optimization and High-Performance Computing
- Understanding Compiler Optimizations — Levels and Flags
- Writing Vectorizable Code — What Compilers Can Accelerate
- Memory Access Patterns — Locality, Stride, and Cache Efficiency
- Profiling and Benchmarking — Measuring Real Performance
- HPC Considerations — Scaling to Large Systems
Chapter 15: Build Systems, Testing, and Modern Toolchains
- The Fortran Package Manager (fpm) — Modern Builds Made Simple
- CMake for Fortran Projects — Cross-Platform Build Automation
- Traditional Makefiles — When They Still Make Sense
- Testing Strategies — Unit Tests and Validation Frameworks
- Static Analysis, Linting, and Documentation Tools
- Summary
Chapter 16: Professional Practices and Legacy Code
- Coding Standards — Naming, Formatting, and Readability
- Defensive Programming — Error Handling and Robustness
- Resource Management — Cleanup and RAII-Like Patterns
- Version Control Conventions — Git Practices for Fortran Projects
- Modernizing Legacy Code — Strategies and Tools
- Summary
Conclusion: The Future of Fortran
- What You Have Learned
- Where Fortran Is Heading
- Why Fortran Still Matters
- Final Advice