I deal in computational solid mechanics and I heard from many people that for a short code best choice is matlab and for large code (more than 1000 lines) obvious choice if fortran. For VUMATS, people use fortran. I will start writing some large codes soon, so I just wanted to know whether should I do it them in fortran? Why not modern programming languages such as c++ or java?
It is somewhat discouraging that some think Fortran is not a "modern" language, while C++ somehow is. Given that Fortran has both object oriented programming and also parallel programming built in, and C++ has only OOP, it is a fairly easy argument that Fortran is more suited for large scientific codes. The Submodule facility is also an aid in such codes. The main detraction for Fortran is that few people outside the HPC community know the language. That is perpetuated partly because people learn computer programming in CS departments where almost no one knows Fortran.
One of the features of Fortran is longevity. If you write the code in Fortran it will likely still work, and people will still be able to read it, decades from now. That is certainly the experience of codes written decades ago. In that time there will be multiple "fashionable" languages with ardent followers that will rise and eventually fade. (Anyone remember Pascal, or Ada?) If you want a fashion language to learn today, you probably should be looking at Python (on the upswing) rather than C++ (being displaced by Python). Or you can go with Fortran, which is arguably a sequence of new languages over the years, all of which have the same name. And are largely backward compatible.
From stack overflow...
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 slow code -- pointers are restricted in such a way that it's immediately obvious if there might be aliasing, as the standard example -- and so the optimizer can go to town on your code. Current incarnations have things like coarray fortran, and do concurrent and forall built into the language, allowing distributed memory and shared memory parallelism, and vectorization.
The downsides of Fortran are mainly the flip side of one of the upsides mentioned; Fortran has a huge long history. Upside: tonnes of great libraries. Downsides: tonnes of historical baggage.
If you have to do a lot of number crunching, Fortran remains one of the top choices, which is why many of the most sophisticated simulation codes run at supercomputing centres around the world are written in it. But of course it would be a terrible, terrible, language to write a web browser in. To each task its tool.
Here is a detailed discussion about it
http://stackoverflow.com/questions/8997039/why-is-fortran-used-for-scientific-computing
My suggestion is to write a lot of subroutines in Fortran and then convert them to shared libraries in python using f2py (http://www.f2py.com/). This will help you to drive your code easily in Python and also give you access to a whole lot of libraries such as numpy, matplotlib, mayavi, pretty plot lib and so on. This would be a very futuristic way of writing a scientific code. Just give it a try... :)
I agree with Pankaj Mishra. In the particular field of finite elements and in my particular case I had no choice. Writing bottom up a finite element program to code one specific element is simply not practical, especially if the element is a complex one. So... you end up using an older program. Most of my experience in research included ADDING functionalities to previous programs (being new element formulations or solvers, etc.). So you build up on previous work recursively... and FORTRAN has always been there. And again, once you move to a new code, you will bring your experience with you, for good AND bad. And this includes proficiency in a particular language.
Pankaj says "to each task its tool", There was an OLD article published in Scientific American (1979) that discussed several programming laguages including FORTRAN (already considered obsolete by some in 1979!) which reached the same conclusion.
Above all because it is fast, compared to interpreted languages, it is relatively simple compared with C, especially when using matrices and arrays, and there is a lot of previous work done on it, and it is simpler to use some pre-existing tools and write your bit of code, rathen than start from scratch. That said, I use C....
I have been developing finite element analysis code last 10 years and all my development uses C\C++ (object-oriented) extensively. There are many math libraries(open source) available that are developed in C\C++. I would strongly recommend use of C\C++ for numerical computation for better code management, extensibility and maintanance. Performance-wise, a good C\C++ code easyly matches performance of Fotran code
One may argue that fortran is outdated and old given that his or her knowledge on fortran advances are not updated.It is true that fortran was left behind for some time (especially when C++ appeared) but after the upgraded f90 came out the statement that fortran is superior when it comes to perform large-scale calculations involving matrices became once more true.Intel visual fortran xe14 compiler is not only fast but also capable of auto parallelization of loops and other parts of the code without the need of any wrapping code.Extensibility and maintenance became very easy through the use of modules thus fortran is far superior when it comes to numerical problem handling . Definitely you will not use it to develop a Web based application, as stated above, given that there are other more suitable languages that would do this much more efficiently. So the question here is what will you use in order to program your application? The answer to that question is:use the language that you know the best.If you not planning to solve problems with millions of unknowns then C++ will do just fine.You can even use GPU (this is also applicable in fortran) to accelerate your calculations and alleviate the speed issue.At the end of the matter your goal is not to race speed wise but to solve in an acceptable time frame your problems at hand.
Regards
Scientists use a variety of languages, not just Fortran.
C an C++ are used, and some people are using Java.
A lot depends on how large the memory requirements and the
computational requirements are.
For large parallel programs, the Fortran + MPI or C+ MPI
combination is hard to beat for performance. Just for the
ability to use multiple terabytes of RAM, these are useful.
MPI originally used with C++, but the C++ bindings were
deprecated, so I'm not sure if anyone is still using that combination.
Unified Parallel C and the Coarray Fortran which is part of Fortran 2008
may make parallel programming in these languages easier.
There was an attempt to make a distributed memory Java work well,
which I believe was called Java Grande, but I don't know if that was
ever successful.
What I'll suggest is to use your software to solve something relatively large and check how long it takes and if you can even solve it.Then study about handling large scale numerical problems and conclude if you can restructure your code to run faster. Invest in your code and give it a chance. This will help you in the programming procedure and gain experience faster than in the case of using a language that you don't know.Fortran has an edge over the pre mentioned languages in the under discussion field of problems.Therefore if you reach a point that your code is not capable in solving efficiently your models, you can consider using fortran.
maybe because the fortran was the only full packed with suitable libraries compiler at the time when most of the scientific softwares like Abaqus were developing. today, these softwares have so many intermittent keywords and libraries written with fortran and if you are interested in using them, you have write a code with fortran.
Seeing this discussion taking a different path, I would like to add something too. If you really do believe in write the code of the future then go for GPGPU. It gives you "the massive parallelism"... I mean its the real deal if you can make your solution algorithms parallel... Being a big python lover myself... I would suggest you write your code in cuda and then drive it with pycuda or go for something like Numbapro which gives access to the LLVM api of cuda.... Depending upon the GPU's you choose between opencl and cuda... But massive parallelism is going to drive this millenium. Now NVIDIA has introduced unified memory in cuda and that is an added advantage considering the amount of time you spend in moving your data to and from Gpu. Not that it will be gone just the fact that you don't have to write few more lines of code that has to do it is a big relief.... To sum up all the jub jub... GPGPU is the future.... I hope this really does take the discussion to a very different path... :)
First of all: Don't use Java! For performance reasons you want to be closer to the hardware; a virtual machine, like Java uses, is not a good choice. Also, Java is not a language made to write down an algorithm (Java is pure object oriented and thus forbidding you to write plain old procedural code).
C could be an option, when you think about performance. But, especially in scientific computing it is easier to write programs in Fortran than in C. Fortran gives you a nicer syntax to handle arrays. More recent standards of Fortran even allow for object oriented programming.
I personally prefer to use C++, even for scientific computing. Fortran has its strengths because of its array notation and powerful compiler optimizations. C++ compilers have caught up to Fortran. From my experience equivalent code (fully object oriented with many nested functions calls in C++ (which are optimized away by the compiler)) is equally fast in Fortran and C++. So, performance is not a point for Fortran anymore. As for arrays, use a library for this in C++, e.g. EigenLib or Armadillo. They will give you similar handy notations for arrays in C++. And they can be equally fast compared to Fortran.
The advantage of C++ is that you can define your own types and overload operators. Operator overloading allows for an almost mathematical notation of computation right within the source code. Defining your own types, e.g. for coordinates, gives you a lot more type safety. Many errors can be caught during compilation instead of after runtime when you figure out that results are wrong. You can even use type checking to prevent errors due to incompatible units (with units I mean things like meters and seconds).
Someone mentioned that MPI dropped support for the C++ API. A good and easy way to get around this is to use Boost's MPI interfaces. They are even nicer and easier to handle than the original MPI interfaces.
I think that there is no reason for Fortran over C++, but a few for C++ over Fortran. I have used both Fortran and C++ for scientific applications, and if I could choose I would always use C++.
PS: BTW, Fortran is a really modern language (although it has a lot of old baggage, but so does C++). For a while Fortran was even more recent than C++ (judging by the publications of new standards).
Andrew,
I do agree with Vijai that looking at massive parallelism is a
good idea.
However, it is the algorithm that is chosen to solve the problem
that determines the inherent parallelism, not the specific hardware
that it is run on.
I definitely disagree with the recommendation of CUDA. That is a
language tied to a specific piece of hardware, and it is never a good
idea to tie your programs to specific hardware, that is what standards
and high level languages are all about. Ask anyone who has
Connection Machine or Maspar C codes lying around. Or programs
for FPGAs or Cell processors, or assembly language programs for
various processors that no longer exist.
We did some testing with CUDA platform and it was a big bottleneck to transfer large data from CPU (host) to GPU (device). Either you need to chnage your algorithm (framework) or you need to target an expensive CUDA hardware/ Recently, unified memory model adapted (not sure this new technology supported in latest NVIDIA cards only or our 2-3 old video card can take the advantage of it). Plus, typical NVIDIA cards are for "single floating" computation, and you need to spend a few thousand dollars to buy more powerful card with "double floating precision"
I agree with some comments posted above that if you are already working with FORTRAN , probably it is best for you. If you are looking for a new language platform, I would still suggest C\C++ .
Andrew,
Fortran should be considered if you plan on sharing your code with other researchers - especially those in the math/science area that are *not* in Computer Science. Many may scoff at my idea, but Fortran has been taught to those other folks for 4 decades while CS has jumped from language to language as its preference for a teaching language (Fortran -> Pascal -> C -> C++ -> Java).
As mentioned, if the project is new from the ground up, then choosing C/C++ might be a better option. If on the other hand you are adding to an existing body of work, then you should be coding in whatever language the rest of the application is using.
Andrew - a google search of "free FEA code" codes brings about many items. One is http://www.oofem.org/en/oofem.html I'm willing to bet that since it has OO in its name that it is C++.
As for which compiler to use, what is your target? By writing in Visual C++ you automatically limit yourself to the Windows environment. gcc can be found on everything from Linux to Mac to super computers to Windows. You could choose to write your code to be as portable as possible, but that might sacrifice a bit of performance as any optimizations will be for that OS or CPU architecture.
Also, if you plan on leveraging existing libraries on the Internet (the oofem.org page makes reference to PETSc), you'll need to remember that C/C++ are row major in their array storage whereas Fortran is column major. Consecutive memory references are layed out as: Row major is a[1,1] a[1,2] a[1,3]...a[1,n] a[2,1] - Column major is a[1,1] a[2,1] a[3,1] ... a[n,1] a[1,2]
@Jerrold
At our university computer scientists are taught Java and mathematicians are taught C/C++. A lot more than half the computer scientists of our university will not be able to write C++ code after they have graduated. As for the mathematicians, only the older people still know FORTRAN. Everyone of the students only knows a little C/C++. Very few of the PhD students work on older code and thus have to figure out FORTRAN on their own. So, I cannot agree that FORTRAN is the way to go if you want to share your code with other researchers. At least not at our university.
@ Andrew
In general you should try to write portable code so that in the end it doesn't matter which compiler you use. I prefer to use Linux for programming because I think it is easier to set up for this task than Windows (especially if you want to use many different libraries in your projects). In many of my projects I have been using Qt for GUI programming. Because of this I am now using Qt Creator as IDE for all my projects (even those not using Qt). The good thing is that it is available for both Windows and Linux. Then it is easy to switch between different operating systems (e.g. home and work).
As for performance of array structures, I think that FORTRAN has already found an optimal solution. No other implementation can be faster than this. But, as I said before, C++ compilers have caught up to FORTRAN and are equally fast. This is especially true if you are using existing libraries for this purpose. They know all the tricks how to write fast code and you can just use this to your advantage. For a longer discussion on using C++ for scientific computation (there are also comparisons to FORTRAN) I like to refer to another post:
https://www.researchgate.net/post/What_are_the_advantages_of_C_over_C_in_numerical_Computations2
There you will find some advice on what traps to avoid and some good practices to write fast code in C++.
It is somewhat discouraging that some think Fortran is not a "modern" language, while C++ somehow is. Given that Fortran has both object oriented programming and also parallel programming built in, and C++ has only OOP, it is a fairly easy argument that Fortran is more suited for large scientific codes. The Submodule facility is also an aid in such codes. The main detraction for Fortran is that few people outside the HPC community know the language. That is perpetuated partly because people learn computer programming in CS departments where almost no one knows Fortran.
One of the features of Fortran is longevity. If you write the code in Fortran it will likely still work, and people will still be able to read it, decades from now. That is certainly the experience of codes written decades ago. In that time there will be multiple "fashionable" languages with ardent followers that will rise and eventually fade. (Anyone remember Pascal, or Ada?) If you want a fashion language to learn today, you probably should be looking at Python (on the upswing) rather than C++ (being displaced by Python). Or you can go with Fortran, which is arguably a sequence of new languages over the years, all of which have the same name. And are largely backward compatible.
I would agree that Fortran has many modern features. But, it also has an old core--older than C++. When C++ has been conceived a few lessons on how to design a language have already been learned. It is never possible to redefine the core of a language (e.g. syntax). But, within this respect C++ is also far from perfect.
Even though the Fortran standard has many modern features the problem is the compilers. As long as the majority of the compilers does not fully support the newer standards Fortran is still perceived as an old language. Only about four or five years ago our simulation code has been transitioned from FORTRAN 77 to Fortran 90. Since then a few newer features (newer than Fortran 90) have been used, but overall it is not modern Fortran. Another problem is that only every other version of Intel Fortran succeeds in compiling all code. So, people are hesitant to switch to a newer version of the compiler (and thus a newer version of the standard) because their existing code might break.
I now heard for the first time that Fortran has parallel programming built in. So, I looked it up and it has only been included in the 2008 standard that has been approved in 2010. So, it is unfair to say that C++ does not include this features. The C++11 standard includes library functions for parallel programming. Just because they used a different approach doesn't mean that it is not a feature of the language. And OpenMP has enabled both Fortran and C++ for a long time to easily parallelize loops. So, Fortran's parallel feature only adds new syntax whereas C++ adds additional approaches to parallelization.
Finally, C++ is certainly not just a fashionable language. It has survived for many years. It will still stay for a while because it is a highly regarded choice for system programming and general application development. There are many scientific libraries available for C++ which makes it also a valid choice for scientific programming.
@Simon / @Bill - please, lets not have a language war :-) Both languages have their advantages and disadvantages. My background was mostly C for 20+ yrs (working at IBM on the development of AIX among other things), but when I moved into the HPC realm (circa 2006) I learned that Fortran was not only *not* dead - but had been enhanced to provide recursion, dynamic memory, structures, and even allowed for slices of arrays (using real numbers as indices). Are all those features necessary? I would say yes to the first three, and never understood the last.
I found that most HPC codes were written in Fortran, in part because they had been around since Cray 1 timeframe, and that was the best performing language - and continues to be so. This was the reason that I mentioned if it was an existing body of code, then writing in the current language was the optimal choice. I also found that certain hardware architectures (IBM's Power) have difficulties with performance when it comes to templates - using the IBM xlC compiler. Not sure if gcc also had that issue.
While it's great that CS students are learning C++ and now Java, my comment about Fortran was geared to the folks I was dealing with - engineers, chemists, and biologists. They could handle the OpenMP and MPI parallelization concepts, writing it in something other than Fortran baffled some of them.
@Andrew - pick the programming language that you can best express your solution in. My point earlier about using existing libraries still holds - be careful of what language they are implemented in.
For a C++ library of reusable code, look to http://www.boost.org/
Dear Adrew, I am still recommending to you to use C++ given that this is the language that you know the best. Just for your info I initiated a small numerical experiment so as to provide some answers to the question on which language is faster (or which compiler is the fastest) when it comes to handle matrices and arrays. Anyone that might be interested in contributing their knowhow and experience in C++ are more than welcome.
https://www.researchgate.net/post/Fortran_vs_C
Regards,
George
FORTRAN is high level language while C++ is intermediate language mean low level as well as high level language. There are many scientific libraries available for C++ which makes it also a good choice for scientific programming, that's why its better than FORTRAN
Modern Fortran is by far the best choice, since:
1) It's a specialised numerics language so it its has the functionality
for scientific programming built in.
2) It is a slightly higher level language than c++ .It allows you to deal with
problems at the array level(not just at the element level) ie slice and dice arrays as needed.
3a) It has built in support for parallelization . ( improved with Fortran 2008)
3b) Works well with OpenMP and MPI
3c )The support for parallelization keeps up with the times that is, 1995 vector machines to 2008 cluster style.
3d) Its installed on any large scale parallel machine.
4 Its very modular.
5 Very nice to program in.
6a) It has a simple data abstraction model.
6 b) It now has support for OO programming.(I don't think it's all that fast as yet )
7) It works well with Octave and Matlab that is, its column major.
8) Its designed to work well with more general languages like c++ and c
9a) Compilers are not too expensive and free if you use gfortran.
9b) At least two free nice IDEs Eclipses and Code Blocks
10 Its Easy to learn. Much easier to learn than say c++.
11) Lots a of source code about.
1a) Bad points IO is still a bit clunky (you can call C however)
1b) If you need fast IO use mpi or more recent libraries.
2) String handing is, I think, still clunky but usable one you became
familiar with it (and maybe add a module or two )
3)It is a specialised language. (this is actually a big plus ) So, if you are doing something other than numerics / science use a language for that job.
4)It uses the c preprocessor (it would be nice its own was supported)
5) Computer Science departments are notoriously ignorant about it.
To lean it:
1) Install gfortran
2) Install Code Blocks.
3) Buy, borrow or download I few books that deal with Fortran 2003 or later.
If a book shows a bunch of goto statements Do not buy or read it. It's old hat.You basically never benefit from a goto statement.
FORTRAN compiler optimize for numeric computation. If you made a bechmark comparation between a numerical program in FORTRAN and any other language, FORTRAN wins.
I personally prefer C/C++ over Fortran for several reasons.
Obviously Fortran has provided more excellent features for computational numerical simulation. I think the biggest selling point is its ability/simplicity to operate data, especially matrix. To some extent, it is similar to Matlab, however added much more computational capability. I think that is why lots of scientist like Fortran because it is relatively easy to start with.
However, C++ is different.
First, it is not matrix-oriented. But there are numerous libraries available for high performance demand. But I want to point out that matrix operation is not the only thing we care about in numerical simulation. In face, I don't care about it at all given that there are many open source math libraries available.
Second, C++ is object-oriented through class/struct, which is the selling point in my opinion. While modern Fortran has some OO features though derived type but it is far from satisfactory. On the other hand, Java and C# are fully OO, however, extensive OO has reduced their performance (JVM and .net framework). In a word, C++ can achieve a best balance between performance and OO structure.
Third, in term of performance, C++ could be as fast as Fortran. I have seldom heard that someone cannot finish a C++ simulation because C++ is too slow. Most likely the performance issue is caused by poor programming designs. Even with the fastest tool, one cannot guarantee the best performance because of our limited skills.
Forth, for large project, as a friend recommended "Usually all kind of optimizations (for performance or for resources) leads to code that is harder to read, understand and maintain. Doing it prematurely can make it much harder in the future when you need to expand or maintain the code. Concentrate on making good, maintainable code first and foremost.", we should focus more on the quality of program/model instead of performance. And I think the nature of C++ has much better support in term of code quality, especially for modern C++. While for Fortran, due to the version changes and language itself, it is sometimes hard to maintenance and extend large project.
I haven't used Fortran for a long time, but that is my thoughts.
Most of the legacy code is written in FORTRAN and C/C++ for obvious reasons and one would not like to rewrite the code. Its best practice to use exiting and use a programming language which can act as a glue. Python was a good candidate but Julia seems to be a better one. Try out some of my books whose links can be found at http://bookmuft.com/my-books/ to learn them from a beginners point of view.