I didn't come across any definitive statistics saying C++ is slower than fortran. Maybe I didn't search thoroughly. I am wondering whether fortran is still faster than C++ for scientific computing?
Asked
Active
Viewed 1,898 times
-1
-
1Fortran and C++ are languages. Languages don't have a "speed", so it's hard to give a precise and definitive answer to this "question". – Kerrek SB May 17 '14 at 22:58
-
The term scientific computing has a very broad perspective. – 101010 May 17 '14 at 23:01
-
1This question may help you: http://stackoverflow.com/questions/146159/is-fortran-faster-than-c – James King May 17 '14 at 23:02
-
I know of at least one Fortran compiler that generates C code. I expect, in most cases, compilers that have same backend will be very similar in speed (e.g. gnu fortran and llvm fortran) will be very similar in performance. Fortran as a language has some restrictions on aliasing that don't hold for C or C++, which allows a good fortran compiler to (sometimes) generate slightly better code than a C compiler, but most of the time, this difference can be eliminated by correct usage of for example `restrict` keyword. – Mats Petersson May 17 '14 at 23:02
-
@Kerrek SB By speed, I mean execution time to execute a program. Fortran has builtin matrix structure, where as C++ does not. And there are many language specific features in both languages. Do they make fortran fster – user3519733 May 17 '14 at 23:03
-
Recent article on this topic in Ars Technica:"Why are some programming languages faster than others? Scientists use Fortran because it's fast, but what makes it so?" by Peter Bright - May 11 2014, 3:00pm EDT – Fortranner May 18 '14 at 01:19
-
There are a lot of structural reasons why FORTRAN compilers routinely generate the fastest code. One not mentioned is the ability of the compiler to generate fixed call blocks. If I have a function with 10 parameters, it is possible for a non-recursive function to simply push the address of the call block then make the function call. In C, that one instruction would become at least 10 instructions. The difference is such that nearly every molecular modeling application is still in FORTRAN. – user3344003 May 18 '14 at 04:19
-
The speed difference was always small, we Fortran programmers usually have other reasons for using it as simplicity, array support and its ubiquity in the field. – Vladimir F Героям слава May 18 '14 at 05:58
1 Answers
1
C and Fortran have been pretty equivalent in speed since C99 introduced the restrict keyword, which allows array processing functions to not worry about overlap between inputs and output, which Fortran has never had to deal with. C++ doesn't have restrict yet, but might someday, which would allow for the same minor optimizations in compilers.
A lot of C++ compilers (e.g., g++) offer support for proprietary __restrict__, etc., keywords that can achieve the same results though, at the cost of compatibility.
Jeff
- 3,437
- 3
- 25
- 35