I was researching this topic for a some time, but I can't find definite answer (and I don't hope to find it there). Is it feasible to do heavy computations using C++? I mean specially computations on large multidimensional arrays.
C++ has mechanisms which can help writing quite clean optimised code (specially templates). I don't know if I remember correctly, but aren't floats in C/C++ promoted in statements to doubles, which can hurt performance? Some of the libraries look good, but how fast and easy are they?
Maybe learning FORTRAN is better alternative. I heard there are new standards which make programming in it more 21st centuary and that it is very popular in scientific community. It is also optimised and easy to use in matrix operations. Does this make learning it a good choice if I want to do computational chemistry, or is it better to learn more C++?

Recommended Answers

All 2 Replies

On PCs there was a speed difference some 30 years ago, but hardware technology has advanced to where there is no longer a speed difference. Here is just one of many threads you can find on the subject.

It is my impression that FORTRAN may be a better language to use than c or c++ for heavy numerical processing. However I havn't used FORTRAN in decades, so that statement may or may no longer be valid.

This is an age old debate. C/C++ vs FORTRAN. Many people who know much more than I do have more informed opinions on it. I'm sure you can find many many forum threads, articles, and peer-reviewed research papers on the subject. However, you must be careful at only looking at very recent data (anything older than 5 years is basically worthless, things change really fast in the world of computing).

As for performance, check this site out. It basically compares almost every programming language out there on a exhaustive number of benchmark tests, and it is mostly compiled from the last 5 years. The conclusion, after looking at many language-to-language comparisons, is that GNU GCC C++ and C are tied at number 1, followed closely (2 or 3 times slower) by Java-6, Ada, and Lisp, and trailing surprisingly far behind are FORTRAN and Pascal (around 5 times slower than C/C++). I'm sure there are other results that contradict that, but this seems like a fairly neutral benchmark test. Beware of some reported results that are sometimes tailored to favour one language over another (classic in the heated Java vs C++ debates).

Generally, many are of the opinion that performance alone is not the biggest factor. Look at this interesting article for example. The point of often made that computing time is cheap, the programmer's time is not. Basically, FORTRAN (at least the older versions that I am familiar with) is difficult to program in. Large software development and maintenance is a killer. So, for that matter alone, C++ would be a better candidate IMO. The preference for FORTRAN in scientific computing is mostly due to legacy (i.e. old people and old libraries).

However, if you are stepping in the world of scientific computing, I guess you can't really avoid FORTRAN much. There are tons of large libraries that are super-optimized and that are written in FORTRAN. However, like many do, you can just code the higher-level stuff in C/C++ and call FORTRAN libraries. But, in terms of learning the language, you will most likely need some knowledge (at least being able to read and understand FORTRAN code). But, C++ would probably be a better language to get a writing proficiency in (because FORTRAN will only be cumbersome to learn and will nurture bad programming style (in the sense that performance comes second to speed of development and maintainability)).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.