-2

For my own entertainment I have decided to create a large scale physics engine. I have experience with Java and C++ but none with Fortran. My understanding of Fortran is that it is used in the scientific industry and is good for large calculations. I decided to use C++ for any gui, sound, user input, etc. that might be added while Fortran would handle the calculations. How easy is it to call Fortran methods from C++? I have googled the matter and haven't found much information. Despite not knowing Fortran I am determined to learn it no matter how strict the learning curve may be (assuming that I will get an appropriate performance increase). Is it practical to use Fortran in this way? Will I get a decent performance increase (for large calculations)? Is Fortran still used in the modern world or is it outdated?

Edit: there seams to be this ongoing pattern of people downvoting without saying what is wrong with the question.

SemperAmbroscus
  • 1,308
  • 2
  • 12
  • 23
  • 2
    Intenet is full of such information. You may also just start by searching on StackOverflow [tag:fortran-iso-c-biding] – Vladimir F Героям слава Apr 25 '15 at 16:41
  • @VladimirF The problem seams to be that while I searched "fortran c++ interoperability" you searched "fortran iso c binding" which yield completely different results – SemperAmbroscus Apr 25 '15 at 16:44
  • @VladimirF the link you gave yielded no results – SemperAmbroscus Apr 25 '15 at 16:46
  • Basically, you use the C interface in both. From C++ you use `extern(C)` and from Fortran `bind(C)`. Than use the common methods of interfacing C and Fortran. – Vladimir F Героям слава Apr 25 '15 at 16:46
  • Just a typo http://stackoverflow.com/questions/tagged/fortran-iso-c-binding – Vladimir F Героям слава Apr 25 '15 at 16:46
  • @VladimirF I had no knowledge of the `bind(C)` function since I have never learned fortran and that still only answers one of my questions – SemperAmbroscus Apr 25 '15 at 16:47
  • 4
    A question "how do I call Fortran from C++?" is potentially useful, but when you come to "Will I get a decent performance increase (for large calculations)?" we have "it depends", but on " Is Fortran .. outdated?" we're far into opinion. – francescalus Apr 25 '15 at 16:48
  • The other parts are just duplicates of http://stackoverflow.com/questions/31672/learning-fortran-in-the-modern-era?rq=1 http://stackoverflow.com/questions/146159/is-fortran-faster-than-c and many others. Please don't start a new flame here! – Vladimir F Героям слава Apr 25 '15 at 16:48
  • @VladimirF the way I see it there is no possible flame war as the two aren't comparable; I believe I read somewhere that they use different paradigms therefor I am asking for the benifit of using them together not one over the other – SemperAmbroscus Apr 25 '15 at 16:51
  • This is an EXTREMELY common flamewar and C++ and Fortran are **direct** competitors in high performance computing. Or just read @BrianTopping's flame starter answer. – Vladimir F Героям слава Apr 25 '15 at 16:55
  • @VladimirF ok I stand corrected – SemperAmbroscus Apr 25 '15 at 16:56
  • 2
    I also don't get why people downvote this question and not just mark it as a copy! There is no need to feel personally insulted. The questions asked are legitimate and the "c++ vs. fortran flamewar" wasn't started by the OP. And even though the internet is full of information on this topic, there is no common opinion and certainly also no general truth. – PeMa Apr 30 '15 at 14:45
  • @SemperSolus I think the appeal of Fortran >= 90 is not the absolute performance (which could also be obtained with good C++ codes), but rather language-level support for easy and efficient handling of multi-dimensional arrays (most notably, the colon operation). Indeed, the almost sole reason that I am still using Fortran is that it provides such array support. So it might be worth to mix Fortran codes if your problem involves heavy use of linear algebra and multi-dimensional arrays (dim >= 3). – roygvib Jun 07 '15 at 04:57

1 Answers1

1

My understanding of Fortran is that it is used in the scientific industry and is good for large calculations.

Fortran is indeed used (still) in scientific and engineering applications, and in many other places as well.

How easy is it to call Fortran methods from C++?

The latest Fortran standard has specific provisions for interoperability with C. Those facilities provide a standard means for C or C++ code to call Fortran routines, and for Fortran code to call C routines and C++ routines having C linkage.

C and Fortran routines have been calling each other much longer than the C interop provisions have been in the Fortran standard, but how that is accomplished without using the interop features is implementation dependent.

I am determined to learn [Fortran] no matter how strict the learning curve may be (assuming that I will get an appropriate performance increase).

Although some aspect's of Fortran's structure make it comparatively easy to optimize for number crunching, you may be disappointed if you expect to see large gains from implementing numerical routines in Fortran instead of C. Your performance is likely to be more related to the algorithm you choose than to the language in which it is implemented.

Is it practical to use Fortran in this way?

Yes.

Will I get a decent performance increase (for large calculations)?

It depends on a lot of factors, but my rough estimate is "no".

Is Fortran still used in the modern world or is it outdated?

It is still used, and the Fortran standard is still maintained and periodically updated.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • thank you I asked for nothing more I don't understand the unjustified downvotes – SemperAmbroscus Apr 25 '15 at 16:49
  • 1
    @SemperSolus I did not vote either up or down your question or this answer, but my feeling is we don't need any new C/C++ vs Fortran here. You can read people's opinion in http://stackoverflow.com/questions/146159/is-fortran-faster-than-c http://stackoverflow.com/questions/2266643/for-what-are-fortran-cobol-and-co-used-today http://stackoverflow.com/questions/31672/learning-fortran-in-the-modern-era But as I said, I can't speak for those who actually downvoted. – Vladimir F Героям слава Apr 25 '15 at 16:53
  • 1
    @VladimirF I never wanted to know which was better because either way I would be using both of them together (perhaps my question was worded wrong). I also want to mention that when googling "Fortran C++ interoperability" none of those results were shown – SemperAmbroscus Apr 25 '15 at 16:58