- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Not trying to start a language war or anything, but I work in a real-time image processing industry where performance is of utmost concern.
Our initial algorithms were written in Fortran back in the 70's/80's, and eventually translated to C. Right now our application uses C++ for infrastructure-related stuff, and C for the algorithms for maximum performance. The C algorithm functions are parallelized using master-worker design pattern. We use Intel compiler. Our platform is Windows x64.
I have never coded in Fortran but heard that it's great for scientific computing, as well as unmatched (?) performance by other language.
So...here's the question: assuming an algorithm is coded efficiently in C and Fortran (i.e. they both describe the same algorithm), would code produced in Fortran be significantly faster than the C counterpart? Assuming that we use Intel compiler for both C and Fortran.
Because if Fortran really is faster, I'm thinking about making an object code out of Fortran and call it from our C++ infrastructure instead.
Thanks!!
S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The main differences are
one compiler may simply be better, or better adapted to your particular situation, than the other.
the fortran library is likely to be better tuned for many mathematical operations -- but you can call it from C if you want.
the fortran language permits the compiler to make certain optimizations that are seldom possible in standard C / C++, mainly due to potential aliasing but also to potential recursion / reentrancy issues. It is usually possible to provide "hints" to a performance-oriented C / C++ compiler that will allow it to make the same optimizations.
In the end, in my opinion, it is easier to express and understand algorithms that involve more advanced data structures in C / C++ than in the fortran that I learned. Modern fortran may be better but it still feels very combersome to me. Since better algorithms beat better code every time, use the language that admits the most natural and most maintainable expression of the algorithm.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Not trying to start a language war or anything, but I work in a real-time image processing industry where performance is of utmost concern.
Our initial algorithms were written in Fortran back in the 70's/80's, and eventually translated to C. Right now our application uses C++ for infrastructure-related stuff, and C for the algorithms for maximum performance. The C algorithm functions are parallelized using master-worker design pattern. We use Intel compiler. Our platform is Windows x64.
I have never coded in Fortran but heard that it's great for scientific computing, as well as unmatched (?) performance by other language.
So...here's the question: assuming an algorithm is coded efficiently in C and Fortran (i.e. they both describe the same algorithm), would code produced in Fortran be significantly faster than the C counterpart? Assuming that we use Intel compiler for both C and Fortran.
Because if Fortran really is faster, I'm thinking about making an object code out of Fortran and call it from our C++ infrastructure instead.
Thanks!!
S.
It's hard to tell a priori. Modern C (as distinct from C++) and Fortran are comparably fast and which you use can be a personal choice unless local policy dictates otherwise. I'm surrounded by Ccolleagues but Iprefer that all my bugs be of the Fortran type if only because I can detect and swat them more easily. Fortran is simple to learn and you can quickly recode a C algorithm and see which is faster (for that algorithm only and assuming both codes are equally well written). Did you know that Fortran 2003 is interoperable with C?
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's hard to tell a priori. Modern C (as distinct from C++) and Fortran are comparably fast and which you use can be a personal choice unless local policy dictates otherwise. I'm surrounded by Ccolleagues but Iprefer that all my bugs be of the Fortran type if only because I can detect and swat them more easily. Fortran is simple to learn and you can quickly recode a C algorithm and see which is faster (for that algorithm only and assuming both codes are equally well written). Did you know that Fortran 2003 is interoperable with C?
Gerry
Oh wow..I never knew modern Fortran is interoperable with C. Just now I also looked up about Fortran on Wikipedia and found that the language is going through a lot of change to support parallelism. How great!
Interesting. Thanks for your thoughts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The main differences are
one compiler may simply be better, or better adapted to your particular situation, than the other.
the fortran library is likely to be better tuned for many mathematical operations -- but you can call it from C if you want.
the fortran language permits the compiler to make certain optimizations that are seldom possible in standard C / C++, mainly due to potential aliasing but also to potential recursion / reentrancy issues. It is usually possible to provide "hints" to a performance-oriented C / C++ compiler that will allow it to make the same optimizations.
In the end, in my opinion, it is easier to express and understand algorithms that involve more advanced data structures in C / C++ than in the fortran that I learned. Modern fortran may be better but it still feels very combersome to me. Since better algorithms beat better code every time, use the language that admits the most natural and most maintainable expression of the algorithm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The main differences are
one compiler may simply be better, or better adapted to your particular situation, than the other.
the fortran library is likely to be better tuned for many mathematical operations -- but you can call it from C if you want.
the fortran language permits the compiler to make certain optimizations that are seldom possible in standard C / C++, mainly due to potential aliasing but also to potential recursion / reentrancy issues. It is usually possible to provide "hints" to a performance-oriented C / C++ compiler that will allow it to make the same optimizations.
In the end, in my opinion, it is easier to express and understand algorithms that involve more advanced data structures in C / C++ than in the fortran that I learned. Modern fortran may be better but it still feels very combersome to me. Since better algorithms beat better code every time, use the language that admits the most natural and most maintainable expression of the algorithm.
I agree with your assertion there. I believe the language that can best solve the given problem should be used.
By the way, let's say if someone use Fortran with CC++ code, how does one go about debugging it? So if we called a Fortan code from C...how does one go about "stepping into" Fortran code if needed be?
My environment is Windows Visual Studio C++.
Thanks,
S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree with your assertion there. I believe the language that can best solve the given problem should be used.
By the way, let's say if someone use Fortran with CC++ code, how does one go about debugging it? So if we called a Fortan code from C...how does one go about "stepping into" Fortran code if needed be?
My environment is Windows Visual Studio C++.
Just do it. It works just as if you stepped into a C routine.
My philosophy on these language wars is that you should choose the language that makes the most sense for that aspect of the application, that you know well and that can be maintained by your organization. No matter how good Fortran is, it's a poor choice if it has to be maintained by people who know only C++. Every language has its strengths and weaknesses. Historically, C/C++ has been weak in array operations compared to Fortran. That's still largely true, but some of the performance issues can be remedied by use of new features such as accelerated valarray.
Modern Fortran is very expressive and does not lack any significant features compared to usable C++. I'll comment that there have been many studies of projects that settled on C++ - the studies found that a majority of these projects never got completed or finished late and had significant maintenance costs. This is more likely to happen when developers are given free reign of all the C+ features and mis-features. Fortran does not have this characteristic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page