c++.chat - C++/C compared to (not vs.) Fortran
- Anuj Goyal (12/12) Aug 28 2004 in what cases would it be preferred to use fortran rather than c++/c? At...
Anuj Goyal <Anuj_member pathlink.com> writes:
in what cases would it be preferred to use fortran rather than c++/c? At the moment, please ignore parallel Fortran compilers and the parallel runtimes. Please concentrate on this question in terms of perofrmance, not necessarily maintainability of the codebase, the "coolness" of the language, or the "object oriented features" that one language lacks and that another language has. Since fortran compilers have been around for so long, are they more optimized than c? It seems that the language is mostly for use in the scientific community and that many libraries are readily available. These libraries boil down to assembly anyways right? what is the difference between using C and using Fortran for libraries? Is it the nature of scientific programming that demands Fortran, or is just that the scientific communities' programmers are more familiar with Fortran?
Aug 28 2004
Ilya Minkov <minkov cs.tum.edu> writes:
Anuj Goyal schrieb:Since fortran compilers have been around for so long, are they more optimized than c?I heard they are able to optimize more agressively, but definately not for the reason of being around longer. The current architectures we use are younger than compilers - DMC is more than 20 years old (previously: Zortech, some other names). GCC is also of comparable age. The performance characteristic of CPUs doesn't look now too much like it was back then. However, there are ways to give hints to C compilers so that they can employ somewhat more agressive optimizations.It seems that the language is mostly for use in the scientific community and that many libraries are readily available. These libraries boil down to assembly anyways right? what is the difference between using C and using Fortran for libraries? Is it the nature of scientific programming that demands Fortran, or is just that the scientific communities' programmers are more familiar with Fortran?With the number of libraries... I don't think it really matters since every mathematical foeld is probably covered in each of the languages many times over. I'm not so sure there is so much "demand" for Fortran... You know, the whole performance difference due to agressive optimizations boils down to perhaps a few per cent - so uncomparably small compared to, say, performance gained by utilizing parallel processing. And the whole small-scale optimization is probably overhyped anyway. I'm getting the impression that scientific community moves to C++ and high-level solutions, which are far from being optimal on the small scale, but are very easy from the usage point of view, and aid in getting an optimal design on the large scale. What i say here about C probably applies to Fortran to a large extent, though i must say that i'm not familiar with it. In C, what you are dealing are separate functions, which are compiled separately and take fixed kind and number of arguments. They must be called, which means some sort of overhead. In C++, the working of typical math libraries is radically different, in part due to Templates. Imagine, for example a matrix library. If you were writing it in C, you would have sets of functions handle matrices of certain fixed sizes, and/or you could have a set of functions to handle matrices of arbitrary size - which is slower. But all funcrions to handle matrices of a fixed size would be very similar among sizes. With templates, you are not limited to that, you can have the library generate the code that fits your size. And inlining has shown to be useful where the work done by functions can often be optimized away. Of course the compiler doesn't always get it perfectly optimal, nor is there much that can be done to improve it, but generally it is acceptable. -eye
Sep 01 2004
Anuj Goyal <Anuj_member pathlink.com> writes:
thanks for your reply Ilya, I also believe that higher level constructs allow people to be more productive. However, I believe that people have not been looking at the proper language. ie Java and python are both decent languages but they suffer from high setup time. Have you heard of APL? It is an extremely fast, productive language that is used in the finance and insurance worlds when dealing with large data sets that need to be manipulated. Current incarnations of APL are j and k. www.jsoftware.com www.kx.com check out my page for examples, I am trying to add 1 example every couple of days. http://goanuj.freeshell.org/k
Sep 02 2004