Fortran vs C++, does Fortran still hold any advantage in numerical analysis these days? [closed]

Fortran has strict aliasing semantics compared to C++ and has been aggressively tuned for numerical performance for decades. Algorithms that uses the CPU to work with arrays of data often have the potential to benefit from a Fortran implementation. The programming languages shootout should not be taken too seriously, but of the 15 benchmarks, Fortran … Read more

Convert integers to strings to create output filenames at run time

you can write to a unit, but you can also write to a string program foo character(len=1024) :: filename write (filename, “(A5,I2)”) “hello”, 10 print *, trim(filename) end program Please note (this is the second trick I was talking about) that you can also build a format string programmatically. program foo character(len=1024) :: filename character(len=1024) … Read more

Why is fortran used for scientific computing? [closed]

Fortran is, for better or worse, the only major language out there specifically designed for scientific numerical computing. It’s array handling is nice, with succinct array operations on both whole arrays and on slices, comparable with matlab or numpy but super fast. The language is carefully designed to make it very difficult to accidentally write … Read more

Learning FORTRAN In the Modern Era

You kind of have to get a “feel” for what programmers had to do back in the day. The vast majority of the code I work with is older than I am and ran on machines that were “new” when my parents were in high school. Common FORTRAN-isms I deal with, that hurt readability are: … Read more

How can numpy be so much faster than my Fortran routine?

Your Fortran implementation suffers two major shortcomings: You mix IO and computations (and read from the file entry by entry). You don’t use vector/matrix operations. This implementation does perform the same operation as yours and is faster by a factor of 20 on my machine: program test integer gridsize,unit real mini,maxi,mean real, allocatable :: tmp … Read more

How does BLAS get such extreme performance?

A good starting point is the great book The Science of Programming Matrix Computations by Robert A. van de Geijn and Enrique S. Quintana-Ortí. They provide a free download version. BLAS is divided into three levels: Level 1 defines a set of linear algebra functions that operate on vectors only. These functions benefit from vectorization … Read more

Reading a binary file with python

Read the binary file content like this: with open(fileName, mode=”rb”) as file: # b is important -> binary fileContent = file.read() then “unpack” binary data using struct.unpack: The start bytes: struct.unpack(“iiiii”, fileContent[:20]) The body: ignore the heading bytes and the trailing byte (= 24); The remaining part forms the body, to know the number of … Read more