Chapter 40 Exercises: The Fortran Career
These are the book's last exercises, and they are unlike the rest. There is little new code to write — you already know how to write Fortran, and proving it again is not the point. The work here is to articulate what you can do, find where it is wanted, and package what you built, so that the competence you have earned becomes visible to the world. Take them seriously: done well, several of these produce real artifacts — a README, an abstract, résumé lines, a shortlist of codes you could contribute to — that you can put straight onto a GitHub profile or into a job application the same afternoon. The last section then sweeps back across the whole book one final time, so that you leave with the arc intact in your memory, not just the final chapter.
Difficulty tiers. - ⭐ warm-up and recall — a few minutes; retrieval and articulation. - ⭐⭐ applied — write, research, or package something real; 15–45 minutes. - ⭐⭐⭐ deeper or open-ended — produces a portfolio-grade artifact or a broad synthesis; an hour or more, and worth it.
Solutions policy. Problems marked with a dagger (†) and all odd-numbered problems have published
solutions in appendices/answers-to-selected.md. The three coding problems (40.5, 40.17, 40.18) additionally
have complete, compilable solutions in code/exercise-solutions.f90. Reflective, research, and résumé
problems necessarily have model answers rather than single correct ones — the value is in doing them for
your own work, against your own real code, not in matching a key. Where a model answer is given, treat it as
a rubric ("a strong answer names X and avoids Y"), not as the only acceptable response.
Part A — Reflect and Articulate (close the loop)
40.1 † ⭐ Break the seal. Retrieve the one-sentence answer to "why learn Fortran?" that you sealed in Exercise 1.28 at the very start of the book — the dated note, commit message, or file you were told to leave for your future self. Write down the answer you would give today. Then, in three or four sentences, compare them honestly: what did your first answer get right, what did it miss, and — most important — what can you now say specifically, with a reason or a measurement behind it, that you could only assert on faith before? The size of that gap is the exercise.
40.2 ⭐⭐ The elevator pitch. Write a 30-second spoken pitch (roughly 75 words) explaining why you work in Fortran, aimed at a technically literate listener who is not a specialist — a hiring manager in an adjacent field, say, or an interviewer's manager who sat in for ten minutes. It must be honest (no "Fortran runs everything"), specific (name at least one real thing Fortran does that they might care about), and it must end with what you personally can do with it. Read it aloud and time it; if it runs long, cut, do not speed up.
40.3 † ⭐ Pick your sector. Of the sectors in §40.1 — national labs, weather/climate, aerospace, energy, academia, finance — choose the one that most appeals to you and write three sentences on why, naming the specific kind of computation you would want to work on there (not just "climate" but "marching a global atmosphere model forward on a big grid," for instance). Keeping this concrete now makes the later research and résumé problems sharper.
Part B — Type, Compile, and Run
40.4 † ⭐ Predict, then run. Read code/example-01-skills-inventory.f90 without running it. Predict
its exact output line by line, including the final readiness: line. Then compile and run it and confirm.
Two follow-ups: (a) why is the percentage exactly 100.0? (b) which single intrinsic function turns the
array of mastered flags into the count, and what would the line print if you deleted the real(...)
conversions in the readiness calculation and relied on integer arithmetic instead?
40.5 † ⭐⭐ Honest self-assessment. Copy the skills inventory and change the flags to reflect your
honest current state — mark as .false. anything you would not yet claim, unhesitatingly, in an interview.
Then answer: if exactly 6 of the 8 skills are .true., what readiness percentage does the program print,
and why? Finally, add one line so the program also prints how many skills remain (the count of .false.
entries) — which intrinsic makes that a one-liner? (A complete solution to the percentage calculation is in
code/exercise-solutions.f90, procedure solve_40_5.)
40.6 ⭐ Trace the internal write. Read code/example-02-portfolio-card.f90. By hand, work out the
exact string that the internal-file write assembles into abstract — remember that i0 prints an integer
with no leading blanks — and predict the full program output. Then run it to confirm. Why does the f6.2
edit descriptor print 100.00 with no leading space?
Part C — Build Your Portfolio
40.7 † ⭐⭐ Write the README. Write the README.md for your heat-solver/ repository. It must have, in
order: a one-line description; a short Physics section (the heat equation
$\frac{\partial u}{\partial t}=\alpha\nabla^2 u$ and the boundary conditions); Build and run instructions
(fpm build && fpm run); an Output section (what files it writes); and — the mark of real scientific
software, and the section most portfolios omit — a Validation section stating how you know the results
are correct (it reproduces the analytical steady state; the stencil converges at the expected order,
Chapter 38). A README without a
Validation section reads as a toy; with one, it reads as science.
40.8 ⭐⭐ Choose a license. Add a LICENSE file to your repository. Pick a specific license — MIT,
BSD-3-Clause, and Apache-2.0 are all permissive and conventional for a portfolio project — and justify the
choice in two sentences. Then answer the question that reveals whether you understand why the file matters:
what, legally, may other people do with a public repository that has no license file at all?
40.9 † ⭐⭐⭐ Write the abstract. Adapt the one-paragraph abstract template from the Project Checkpoint so that every single clause is true of your actual solver. If your code does not yet do something the template claims — MPI, say, or VTK output — either cut the clause or go make it true; do not ship an abstract your code cannot back up. This paragraph will sit at the top of your README and near the top of your résumé's project section, so it is worth several drafts. When you finish, read it beside your source tree and check that you could point to the file behind each clause.
40.10 ⭐⭐ Caption the figure. Write a two-to-three-sentence caption for your steady-state visualization (the Described Figure in the Project Checkpoint). A good scientific caption does three things: it says what is shown (the domain and the field), it explains what the colors mean (the temperature scale), and it states what physical result it demonstrates (heat diffusing from the hot edge to a steady state). Avoid decoration; a caption is information, not a title.
Part D — Research It (real-world)
40.11 † ⭐⭐ Read an open code. Find one open-source scientific Fortran project on a code-hosting site
(the fortran-lang organization is a good start, but any real scientific code counts — climate, astrophysics,
materials, CFD). Report its name, its scientific domain, and a sketch of its top-level directory
layout. Then map two of its directories onto the architectural roles from
Chapter 36 — which is the
library (src/), which enforces correctness (test/), which holds the docs? Do this by classifying
directories by role, exactly as §36.1 taught, without needing to read a single source file.
40.12 ⭐⭐ Read a real job posting. Find one currently posted job (at a lab, an agency, or a company) that lists Fortran among its requirements. List the other skills it asks for. How many of them does this book cover — count them. The point of the exercise is to see, in a real advertisement rather than a textbook's claim, that Fortran almost never travels alone: it comes paired with Python, an HPC toolchain, numerical methods, and software engineering. (Do not invent a posting — the value is entirely in reading a real one.)
40.13 † ⭐⭐⭐ Find a first contribution. In an open code of your choice, read the CONTRIBUTING.md and
identify one concrete, newcomer-sized task you could plausibly do — a documentation fix, a missing test, a
clearer error message, a small optimization in a loop you could profile. Describe the task in a few sentences,
say which chapter's skills it would use, and estimate how long it would take you. You do not have to submit it
yet — but by the end of this exercise you should be able to, and Case Study 40.1 walks the full loop if you
want to.
Part E — Résumé and Framing
40.14 † ⭐⭐ Write the lines. Using the illustrative templates in §40.4, write one skills line and one project line for your own Fortran work. Every claim must be true of what you have actually done; if you have not measured a speedup, do not state one. Name specific methods (finite differences), specific libraries (LAPACK, f2py, fpm), and specific engineering (regression tests, CI) — the concreteness is what a specialist reader trusts.
40.15 ⭐ Reframe the weak bullet. Rewrite the legacy-only résumé bullet "Maintained Fortran code"
into an HPC-framed bullet that names concrete, specific skills (modules and intent, structured control flow
replacing GOTO, parallelism, regression testing) — without adding anything untrue. Then, in one
sentence, explain why the two bullets describe the same work but summon opposite mental images in the reader.
40.16 † ⭐⭐ Defend the pairing. In three or four sentences, explain why "modern Fortran + Python + HPC toolchain" is a stronger résumé profile than "Fortran" alone. Your answer should make the point that the pairing signals a rare judgment — knowing which work belongs in a fast compiled language and which in a productive scripting one — and it should name the tool (Chapter 15) that bridges the first two.
Part F — Back of the Envelope / Design
40.17 † ⭐⭐ Memory footprint. Write a program that computes the memory a single $N \times N$ field of
real(dp) occupies, in bytes and mebibytes, for $N = 1000$. Report both numbers. Then answer two questions
in a comment: (a) why does a working explicit solver need to budget roughly twice this figure? (b) roughly
how much memory would one field of a $10000 \times 10000$ grid need — the kind of estimate you would do before
requesting nodes on a cluster? (Solution: code/exercise-solutions.f90, solve_40_17.)
40.18 ⭐⭐ Parameterize the card. Extend the portfolio-card idea so the grid size and step count are
variables, and use an internal-file write to assemble a project-abstract string from them. Print the abstract
for a $512 \times 256$ grid run for $10000$ steps. Then adapt it once more to your own solver's real
parameters — this is the string that goes into your README. (Solution: code/exercise-solutions.f90,
solve_40_18.)
40.19 ⭐⭐⭐ Future work. Write a "Future Work" section for your solver's README: three concrete
extensions you could make, each tied to a specific chapter and each phrased as a real task rather than a wish.
Good candidates: Neumann or periodic boundary conditions
(Chapter 24); GPU offload with
OpenACC (Chapter 35); HDF5 or NetCDF
output for large runs (Chapter 25);
an implicit time step via LAPACK dgesv (Chapter 21).
A "Future Work" section signals a code that is alive, not abandoned.
Part G — Interleaved (broad review across the book)
A sweep across the whole book. One or two sentences each; if a question is fuzzy, the linked chapter is where to refresh it. Answer from memory first — retrieval is the exercise.
40.20 † ⭐ (Ch 3) What is 5/2 in Fortran when both operands are default integers, and what single
change makes the result 2.5?
40.21 ⭐⭐ (Ch 5) Fortran arrays are stored in column-major order. In a nested loop over a 2-D array, should the inner loop run over the first index or the second, and why does the choice matter for speed?
40.22 † ⭐ (Ch 8, 17) What modern construct replaced the FORTRAN 77 COMMON block for sharing state,
and give two concrete advantages it brings.
40.23 ⭐⭐ (Ch 24) What does the CFL condition constrain in the explicit heat solver, and what happens numerically if you violate it?
40.24 † ⭐ (Ch 15) Name the tool that wraps a Fortran routine as an importable Python module, and give the one-sentence reason to pair Fortran with Python at all.
40.25 ⭐⭐ (Ch 27) State the two 1950s design decisions that let Fortran compilers produce exceptionally fast numerical code, and for each say in a few words why it helps.
40.26 † ⭐⭐ (Ch 21) Which LAPACK routine solves $A\mathbf{x} = \mathbf{b}$ for a general dense matrix in double precision, and how do you decode its four-letter name?
Part H — Capstone Reflection and Synthesis
The last four problems ask you to hold the whole book in view at once. They are open-ended by design; the value is in the synthesis, not in a right answer.
40.27 † ⭐⭐⭐ The arc in a paragraph. In one paragraph, trace the heat solver from the two-sentence problem you sealed in Chapter 1's checkpoint to the packaged portfolio piece of this chapter, naming the single most important thing each Part (I through IX) contributed to it — Part I gave it arrays and procedures, Part V gave it the finite-difference core, Part VIII made it parallel, and so on. If you can write this paragraph, you understand the book's structure, not just its pieces.
40.28 ⭐⭐ Teach it back. Pick the one concept from anywhere in the book that you found hardest to grasp the first time, and write a four-sentence explanation of it for a peer who has not read the book. Explaining a thing simply is the surest test that you own it; if you cannot, that is the chapter to revisit before your first interview.
40.29 † ⭐⭐ (Ch 31) State Amdahl's Law in words, and say what it implies about the maximum speedup the solver's parallelization can ever achieve if some fixed fraction of its runtime is inherently serial. Why does this mean "parallelize the hot loop" and "reduce the serial fraction" are both worth doing?
40.30 ⭐⭐⭐ The next problem. Name a new scientific problem — not the heat equation — that you could now tackle by reusing the structure of your solver (a field on a grid, a time loop, a stencil update, validated output). Say which two chapters' methods you would reuse unchanged, and which one part you would have to replace. This is what it means to have learned not a program but a way of building them.
This is the last exercise set in the book. When you have broken the seal on your Exercise 1.28 answer, written your README and abstract, drafted your résumé lines, and found one open code you could contribute to, you have turned forty chapters of learning into something the world can see — and something you can act on this week. Go do it.