r/fortran • u/UncleSlacky • 2h ago
r/fortran • u/GatesOlive • Jan 03 '19
I'm curious, what do you use Fortran for currently?
As the wide majority of programmers I talk to considers Fortran to be a dead language, I'm curious of what you are all doing with it.
I'll start by saying I learned it in University in 2009 and taught it from then on to new freshmen.
Thanks!
r/fortran • u/johnwcowan • 2h ago
Is there a way to express the KIND of a literal constant of type REAL?
This would correspond to the traditional use of D instead of E as the exponent marker for double-precision literals.
r/fortran • u/Beliavsky • 5d ago
Ofort: a Fortran interpreter in your browser
Ofort is a Fortran command-line interpreter and interactive REPL written in C. Because there is no compilation step results are immediate for small programs, but for large problem sizes run times can be much higher than for compiled programs. You can try it at https://beliavsky.github.io/ofort/ . There are modes for running entire programs and for running lines of code in a REPL. In the REPL there are panes showing results and a list of declared variables, pictured below. You can also download ofort from https://github.com/Beliavsky/ofort and run it locally. It is MIT licensed.
r/fortran • u/alexis_placet • 14d ago
From Punch Cards to the Browser: Fortran Comes to JupyterLite
Some weeks ago I shared a post about using Fortran into JupyterLite. Here an blogpost about it.
You can now try it easily here: https://notebook.link/@anutosh491/fortran
Update: GraphiC 2026 (Zero-Dependency Scientific Graphics) — Standalone ZIP Distribution, Native fpm Workflow, Continuous Colormaps & 4-Way Language Parity (C, Modern Fortran, Python, Java)
Hi everyone,
Following up on our earlier discussion about modernizing GraphiC (the lightweight scientific plotting engine originally developed at Oak Ridge National Laboratory and Scientific Endeavors Corp), we wanted to share a major progress update, architectural changes based on community feedback, and the release of GraphiC v7.3.0.
The core design philosophy remains unchanged: zero external dependencies (pure standard libc/libm—no Qt, OpenGL, X11, Cairo, or FreeType), sub-2ms cold-start latency, and an ultralight footprint (~655 KB static library) capable of rendering thousands of publication-grade figures per minute directly in-process from simulation codes.
Here is what's new in the latest release:
1. Simplified Standalone Distribution (No Git / Token Friction)
Based on feedback regarding external git dependencies and token management in commercial/academic environments, we have eliminated external Git dependency requirements:
- Standalone ZIP Archives: Both the free GraphiC 2D Community Edition and GraphiC Professional are distributed as self-contained downloadable ZIP archives.
- Local Repo Freedom: Unpack it into your workspace or project tree. Users can initialize their own internal Git repositories if desired without worrying about remote access tokens, submodules, or network firewalls on compute clusters.
2. Native Fortran Package Manager (fpm) Integration
For the computational Fortran community, integrating GraphiC into modern fpm projects is now a 2-line configuration:
toml[dependencies]
graphic = { path = "../GraphiC" }
- Automated Mixed-Language Builds:
fpmautomatically compiles both the core C engine and the Modern Fortran 2003ISO_C_BINDINGmodule together—Fortran users do not need to run a C compiler manually or write build glue. - Broad Compiler Support: Out-of-the-box compatibility tested across GNU
gfortran(4.8+), Intel oneAPI (ifxandifort), LLVMflang, NVIDIA HPC SDK (nvfortran), and NAG (nagfor). - Instant Execution: Run included scientific examples immediately with:bashexport GPC_NONINTERACTIVE=1 fpm run --example sample fpm run --example bess3d
3. Continuous TrueColor Scientific Colormaps
Vector plots can have perceptually continuous shading due to our adoption of the SVG format. We have added 7 mathematically calibrated, continuous 256-node colormaps designed for perceptual uniformity across displays, print, and grayscale reproduction:
- Perceptually Uniform:
VIRIDIS(0),PLASMA(1),INFERNO(2),MAGMA(3). - Diverging & Spectral:
COOLWARM(4),RAINBOW(5), and GoogleTURBO(6). - O(1)O(1)O(1) Fast Evaluation: High-throughput scalar-to-color mapping (
gpc_get_color,gpc_colormap_eval) and continuous high-density scatter plotting (gpc_scatter). - Linear Vector Gradient Color Bars (
ColorKeyGradient): Emits hardware-accelerated SVG<linearGradient>definitions with calibrated numerical tick labels and bounding frames. - Turbulence Showcase: Added shaded graduated color test plot rendering 7,850 experimental points shaded by density.
4. True 4-Way Language Parity (C, Fortran 2003, Python 3, Java 22 FFM)
Every routine in the library now features 100% signature and parameter parity across all 4 supported languages:
- C / C++: Clean ANSI C API with unified headers (
graphic.h). - Modern Fortran: Strict
ISO_C_BINDINGmodules (graphic.f90,graphic_iso.f90) with type-safe interfaces and array descriptors. - Python 3: Both procedural and object-oriented
FigureAPIs with Jupyter Notebook inline display and automatic context manager cleanup (with Figure(...) as fig:). - Java 22+: Modern Foreign Function & Memory (FFM / Project Panama) API—direct zero-overhead off-heap calls without JNI boilerplate.
5. Smart Vector Output, Auto-Cropping & Telemetry
- SVG Auto-Cropping (
svgcrop): Automatically calculates tight vector bounding boxes with a default 0.25" publication margin, eliminating oversized 8.5"×11" white space when embedding figures into LaTeX or papers. - Desktop Auto-Preview (
svgopen): Native OS dispatch (openon macOS,starton Windows,xdg-openon Linux) to view rendered SVG or interactive pan/zoom HTML5 plots. - Headless Telemetry Streaming (
svgpush): Directly streams rendered SVG payloads to remote dashboards or cloud compute endpoints over HTTP/HTTPS POST—ideal for headless clusters and IoT monitoring.
6. 263-Page Reconstructed Technical Manual
We completed a major overhaul of the reference manual (available as a clean vector PDF):
- 91-Section Table of Contents: 100% clickable internal hyperlinking in all PDF viewers.
- 203-Function Master Index: Every routine cross-referenced with operational level, source mapping, and multi-language parity status.
- 26 Visual Computational Recipes: Step-by-step recipes covering aerospace queuing models, orbital trajectories, 3D Bessel surfaces, contour projections, and spectral waterfall plots.
- Publication Architecture Diagrams: High-resolution vector diagrams detailing the dual typography pipeline (Hershey stroke fonts + TrueType quadratic Bézier engine).
Quick Comparison: Community vs. Professional
| Feature | 2D Community Edition (Free / Open Core) | Professional Edition (Commercial) |
|---|---|---|
| License | Standalone Free Archive | Commercial Single-Seat / OEM |
| Core 2D Plotting | Full (Linear, Log, Polar, Bar, Pie, Histograms) | Full (Linear, Log, Polar, Bar, Pie, Histograms) |
| Typography | 23 Hershey Vector Fonts + TrueType Bézier Engine | 23 Hershey Vector Fonts + TrueType Bézier Engine |
| Continuous Colormaps | Viridis, Plasma, Inferno, Magma, Turbo, etc. | Viridis, Plasma, Inferno, Magma, Turbo, etc. |
| Language Bindings | C, Modern Fortran, Python 3, Java 22 FFM | C, Modern Fortran, Python 3, Java 22 FFM |
| Build Systems | fpm, CMake, GNU Make, MSVC Makefile |
fpm, CMake, GNU Make, MSVC Makefile |
| Advanced 3D & Contours | — | 3D Hidden-Surface Meshes, Contours, Cross-Sections |
| Specialized Engineering | — | RF Smith Charts, Ternary Phase Diagrams, Waterfall Plots |
Quick Modern Fortran Example (fpm)
fortranprogram quickstart
use graphic
implicit none
real, dimension(100) :: x, y
integer :: i
do i = 1, 100
x(i) = (i - 1) * 0.1
y(i) = sin(x(i)) * exp(-x(i) * 0.1)
end do
call gpc_bgnplot()
call gpc_svgcrop(0.25)
call gpc_title("Damped Harmonic Motion", "Time (s)", "Amplitude (V)")
call gpc_graf("0 2 10", 0.0, 2.0, 10.0, "-1 0.5 1", -1.0, 0.5, 1.0)
call gpc_color(1) ! Blue
call gpc_curv(x, y, 100)
call gpc_endplot()
call gpc_svgopen("") ! Launches default browser to view vector SVG
end program quickstart
Getting the Release
- Official Website & Docs: https://jamesrome.com/GraphiC2026
- Full Technical Manual: Download the 263-page GraphiC_Modern_Manual.pdf
- Community Edition Download: Free standalone ZIP available on the site.
- Professional Edition: Available via Lemon Squeezy with full 3D, specialized engineering modules, and more customization options.
We'd love to hear your feedback on the fpm workflow, language bindings, or any visualization bottlenecks in your current simulation pipelines!
r/fortran • u/KalKapone • 16d ago
Why doesn't my Fortran stencil code scale past 2 threads? A short intro to roofline analysis (Jacobi / red-black Gauss-Seidel + likwid)
Latest post in my series on iterative solvers for the 2D Poisson equation in modern Fortran
Some context: my OpenMP Jacobi and red/black Gauss-Seidel kernels scale almost perfectly with threads on a 512² grid, but on 2048² the speed-up basically stops after 2 threads. Rather than guess, I built a roofline model of my laptop from three numbers measured with likwid-bench (peak flops, DRAM bandwidth, L3 bandwidth), and wrote it as a small parametric LP in sweeps/s.
What I found:
- Both kernels have an arithmetic intensity of ~0.25 flop/byte, so they are memory-bound at both grid sizes. What changes is whether the working set sits in L3 or DRAM.
- For 2048² on 8 threads, the model predicts 279 sweeps/s. Jacobi measures 272. Gauss-Seidel measures 219, and the gap is explained (plausibly, at least) by read-for-ownership traffic from the red/black stride, which brings the prediction down to 209.
- The model is far from perfect. It drifts by up to ~50% for L3-resident Gauss-Seidel at high thread counts, and I had to hold the DRAM bandwidth flat rather than use the declining Triad curve. The post is upfront about both.
- Bottom line: both kernels already run about as fast as the machine allows (5-7 Gflops/s vs ~483 Gflops/s peak). The remaining lever is temporal blocking, which I don't cover, or reducing the number of sweeps (SOR, next post).
I'm using likwid to the best of my understanding, so I'd really appreciate feedback from people with more experience, especially on the RFO accounting and on how to properly measure DRAM traffic with likwid-perfctr for these kernels. If you've done temporal tiling on stencils in Fortran, I'd love to hear how it went.
r/fortran • u/KalKapone • 23d ago
Red/Black Gauss-Seidel: getting loop-carried dependencies to actually disappear (not just shrink)
A follow-up to my last post here on unrolling Gauss-Seidel for the 2D Poisson equation.
Short recap of where that left off: unrolling + algebraic rewriting cut the loop-carried dependency and got GS running 6x faster than the textbook lexicographic kernel, matching (and slightly beating) Jacobi in serial. Looked like a win. Then I turned on multithreading, and Jacobi pulled 5x ahead, because the unrolled GS kernel still couldn't be vectorized. The dependency chain was shorter, not gone.
This post goes back to basics: is the sequential dependency actually inherent to Gauss-Seidel, or just an artifact of how the grid points happen to be ordered? Answer: the latter. Red/black checkerboard ordering removes it almost entirely, derived not just by intuition (every red point depends only on black neighbors and vice versa) but formally, as an instance of block Gauss-Seidel on a permuted SPD system, with the usual convergence guarantees.
Results: loop-carried dependency effectively drops to nothing (confirmed via OSACA analysis of the generated assembly), SIMD vectorization comes back for free, and for the first time in this series GS actually scales with thread count right alongside Jacobi.
Also in there: walking through the compiler-generated assembly to see exactly why a kernel fails to vectorize (mnemonic-level, not just "the compiler didn't do it"), and using OSACA to quantify port pressure / critical path / LCD rather than just eyeballing it.
Link: https://loiseaujc.github.io/posts/blog-title/redblack_gauss_seidel.html
r/fortran • u/iamperson_-_ • 28d ago
How to loop through lines in a file
Currently, to run a Fortran file, I need to execute the line: file.exe number text in w64devkit. I need to loop through each line in a text file and run the code each time with a different input for text but same input for number. How do I automate this? Also, would it be possible to save all results to a csv file?
r/fortran • u/KalKapone • Sep 15 '26
Reducing Gauss-Seidel's loop-carried dependency from 12 to 2 cycles/element with loop unrolling (OSACA analysis)
Author here (again). Follow-up to an earlier post where I showed a Gauss-Seidel kernel converging in half the iterations of Jacobi but running 4-5x slower per sweep, due to a loop-carried dependency from the in-place update. This post uses OSACA (open-source static code analyzer) to measure that dependency in actual CPU cycles, then applies loop unrolling with an algebraic substitution to reduce it from 12 to 2 cycles/element, bringing per-sweep performance close to Jacobi's while keeping the faster convergence.
Also ran three separate compilation experiments (no optimization, -O3 without vectorization, -O3 with vectorization) to isolate what's actually driving the speedup. Short version: it's the reduced dependency letting the scheduler overlap work, not vectorization. Neither Gauss-Seidel kernel ever gets vectorized, with or without the flag. Happy to go into the Fortran, the assembly, or the OSACA workflow itself.
u/mylarmalediction: I guess this will answer you question about ILP vs vectorization as the source of the speed-up for Jacobi.
r/fortran • u/Prestigious_Soft9133 • Sep 13 '26
I wrote a calculator in 77 million lines of Fortran. It doesn't compile.
I wrote a calculator in Fortran. It supports exactly three operations:
addition, subtraction, and multiplication. Input range is 0 to 5000 for
both operands.
Instead of actually calculating anything, it uses a massive SELECT CASE
table. Every possible combination of inputs is hardcoded. There is no +
in the codebase that adds anything at runtime. No - that subtracts.
No * that multiplies.
It just looks up the answer.
The result:
75,091,301 lines of Fortran
73 modules, each ~43 MB
2x the size of the Linux kernel
I tried to compile it. My machine has 32 GB of RAM. It was not enough.
r/fortran • u/KalKapone • Sep 12 '26
Gauss-Seidel is faster than Jacobi. Or is it?
Author here. Started a series working through classic iterative solvers for the 2D Poisson equation in Fortran. This is actually the second post (the first one being on Jacobi). Here, I dig into a genuinely counterintuitive result: the convergence theory for Gauss-Seidel checks out (half the iterations vs Jacobi, confirmed numerically), but the actual wall-clock time is 4-5x worse. Turns out it comes down to a single line: updating the array in place instead of into a fresh buffer and the loop-carried dependency that introduces, which stops the compiler from vectorizing the loop at all. In an upcoming post, I'll actually show how an open-source static analyzer can help you figure this out, and how simple algebra can be used to unroll the kernel and get rid of this loop-carried dependency.
Happy to talk Fortran/gfortran specifics or the discretization itself.
r/fortran • u/alexis_placet • Aug 28 '26
Fortran now runs directly in your browser through Jupyterlite
Enable HLS to view with audio, or disable this notification
Anutosh Bath and Ondřej Čertík brought LFortran to Jupyterlite
There is a demo here: https://notebook.link/@anutosh491/fortran
source: https://lnkd.in/p/eR49Jve6
r/fortran • u/InfamousEgg6354 • Aug 27 '26
PRIK – Generate native Python bindings from Fortran (with editable API contracts)
Hi everyone,I’ve been working on an open-source tool called PRIK (Python Runtime Interop Kit) that generates native Python bindings from Fortran (and C) source.
Basic usage:
pip install prik
python3 -m prik my_module.f90 --out my_module
This produces an importable Python extension.
The main idea is that the Python API doesn’t have to mirror the native one. PRIK generates an editable `.pyi` contract that you can modify to:
- rename procedures
- turn them into methods
- hide arguments
- return native outputs as Python values
- support overloads and callbacks
…all without changing the original Fortran/C code.
It currently supports modules, derived types (as Python classes), NumPy arrays, strings, allocatables, pointers, optional arguments, generics, callbacks, and more.
I’ve been testing it on real libraries rather than just toy examples:
- BLAS (155 routines)
- LAPACK (127 double-precision routines)
- FFTPACK
- MINPACK (including callbacks)
- BSPLINE-FORTRAN (modern Fortran classes)
C support exists but is less mature (tested with libm and TA-Lib). Still alpha, so the API may change. Fortran support is currently much stronger than C.
Docs: https://pynumlab.github.io/prik/
GitHub: https://github.com/PyNumLab/prik
Feedback, bug reports, or “does this work with my code?” experiments are very welcome!
r/fortran • u/cannyshammy • Aug 18 '26
I got a realtime database subscription working from modern Fortran
Not sure how useful this is beyond the amusement value, but as part of an experiment making Convex clients in 100 programming languages, I ended up with a native Fortran client that can query, mutate and hold a realtime WebSocket subscription.
A few bits I found genuinely interesting:
- Deferred-length allocatable strings make assembling JSON much less painful than I expected.
- Results come back through compiler-enforced intent(out) arguments.
- A live update is exposed as a blocking convex_live_next call, which feels oddly natural in Fortran.
- ISO_C_BINDING is only used at the transport boundary. The Convex protocol and subscription state live in Fortran, with libcurl/OpenSSL handling the network plumbing.
It is built with GNU Fortran 14.2 and the HTTP and Live paths pass the shared conformance suite. It is still an educational experiment rather than something I would recommend putting into production.
The Fortran implementation and write-up are here:
https://github.com/mikecann/the-convex-100-language-challenge/tree/main/fortran
I also made a video about the slightly ridiculous process of building all 100 clients:
For transparency, I work at Convex. This is unofficial and open source, not a new supported SDK.
r/fortran • u/EvanEverywhere • Aug 11 '26
The Past, Present & Future of Programming Languages • Kevlin Henney • YOW!
r/fortran • u/8bitjam • Jul 17 '26
Translated DGGES to Go
I’ve been working on my fork of Gonum and recently translated the Netlib LAPACK reference implementation of DGGES and its supporting routines into pure Go.
For transparency, I definitely used Codex and Claude Code throughout the process, and I’m pretty sure Gemini helped with a few parts along the way as well.
This wasn’t a blind translation. The majority of the work was understanding decades-old Fortran, preserving the algorithm, adapting it to idiomatic Go, validating numerical behavior, and tracking down subtle bugs.
I know AI-generated code can be a sensitive topic in open source. My view is that these tools are just that; tools. They can dramatically speed up tedious translation work, but correctness still depends on careful review, testing, and understanding of the underlying numerical algorithms.
r/fortran • u/TesseractBoy6000 • Jul 14 '26
Differentiable Fortran with LFortran and Enzyme
r/fortran • u/Knarfnarf • May 28 '26
Lottery win strategy
Hello all!
I quickly wrote this in response to a news article about a girl getting a lottery win and taking what I thought was the obvious choice; $1000/wk for ever...
Does this look right?
! Program Lottery Win
! Written by Knarfnarf
! Created May 19, 2026
! Version 0.1a
! Description: Checking my thoughts about winning the lottery.
program LotteryWin
use AnsiModule
implicit none
real :: Principle, Payments, Interest, Temp, Total, Paying
integer :: Year, Week
call ClearScreen()
Print *, "Lets see if the girl who took the 1000 per week will eventually break even..."
print "(a,$)", "Please enter the Principle: "
read *, Principle
print "(a,$)", "Please enter the Payments: "
read *, Payments
print "(a,$)", "Please enter the Interest: "
read *, Interest
Interest = Interest / 100
print "(a,$)", "And how much is she going to pay herself per week? "
read *, Paying
print "(3/,a)", "Assuming start at 20 and death at 85."
print *, ""
Year = 20
Total = Principle
do while(Year .le. 85)
Week = 1
do while(Week .le. 52)
Total = Total + Payments
Total = Total - Paying
Week = Week + 1
end do
Temp = Total * Interest
Total = Total + Temp
print "(a,i3,a,f0.2,a,f0.2)", "Year ", Year, " She made $", Temp, " interest and has $", Total
Year = Year + 1
end do
end program LotteryWin
Which results in this if she takes the $1000 per week, makes 4.5% yearly and splits it $500 income per week;
Year 85 She made $448,950.72 interest and has $10,425,633.00
Or this if she takes the $1000000, makes 4.5% yearly and pays herself $500 income per week;
Year 85 She made $337,680.91 interest and has $7,841,701.00
* commas added after for legibility.
r/fortran • u/Beliavsky • May 17 '26
Fortran For C Programmers
flang.llvm.orgI am posting this guide, from the developers of flang, because people, often with a C or C++ background, often ask how to get started with Fortran.
r/fortran • u/Sgeo • May 16 '26
Snoopy calendar history?
There's a famous program that creates a "Snoopy" calendar.
https://gunkies.org/wiki/Snoopy_Calendar has a copy of a version modified by T. M. Kennedy in 1984.
Does the original version exist somewhere? Do we know who wrote it? I saw someone offering a copy on Github a few years ago but I don't know if that ever actually happened.
Incidentally, despite the comments in the modified version suggesting it should work on an IV compiler, it doesn't. After fixing the syntax error in snppic with INUM(I) in the do loop (easy to just do INUMI=INUM(I) first and use INUMI, the bound is sometimes -1. It encounters the issue where DO loops in some IV compilers execute at least once (66 says the scenario is not allowed, I guess that's FORTRAN-speak for undefined? 77 says the loop occurs 0 times). Easy to change the condition above it from IF (INUM(I) .EQ. 0) GOTO 40 to IF (INUM(I) .LE. 0) GOTO 40
r/fortran • u/Lamda-f90 • May 13 '26
Here is some code examples for new Fortran programmers.
A request for help led me to go through my old Fortran codes. For that reason, I gathered some old programs I found in this repo: https://github.com/foxapiens/Fortran-Starter . And maybe I will continue adding code files and information about their purpose here. At least, it may be useful for beginners.
r/fortran • u/Aggravating_Lie7356 • May 13 '26
Help regarding where to start fortran
Hi, so I have a background in c++ and matlab in programming. I started my phd and my prof asked me to move to fortran. I want to ask how should I start and where to start in fortran. At the moment I know nothing in fortran. Can you share some sources or material for me to start. Or where do you guys started. Thank you