LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-07-2007, 05:49 PM   #1
andrews-mark
Member
 
Registered: Feb 2007
Location: London
Distribution: debian
Posts: 108

Rep: Reputation: 15
is fortran worth learning anymore?


This may be a stupid question, or a question with no answer, and it might annoy some that I am asking it, but still I am going to ask, Is fortran worth learning anymore, or does it have an advantages over alternatives like C/C++ in numerical/scientific computing?

Currently, for numerical programming I use both python and C. Would I be better off using fortran instead of C? I am quite unsure about this because on the one hand I don't really know many people who program in fortran, but on the other hand I have heard people say that fortran still is the very best, and fastest, language for numerical computing.

Does anyone have opinions about this? In particular, is fortran faster than C for numerical computing?

Also, even though I do everything in linux and am really only interesting in fortran on linux, because this question is not really specific to linux, I am putting it in the "non *nix / programming" forum.

-mark
 
Old 10-07-2007, 06:46 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Personally, for anything computational I use Common Lisp.

Which language you use for numerical computation is really up to you. Really, asking this question to the community will more than likely leave you asking even more questions, and you being even more confused about this situation.

My suggestion would be to install a Fortran compiler/interpreter (I'm not quite sure how Fortran is dealt with in that aspect), and write an example program. See if it's something you would be willing to put up with for that few extra microseconds of computational speed.

I deal with Common Lisp simply because it strikes me as a very elegant, and refined, language. The syntax may look a little messy, but when you get the hang of reading Lisp it's something to behold.

As an example, I wrote a Sieve of Eratosthenes algorithm in Java and Lisp: the Java version took upwards of 3 hours to find primes between 2 and 1 000 000. The corresponding Lisp version took less than 5 minutes.

Essentially, it's all about what you're comfortable with. If you start writing computational programs in Fortran and you find yourself really enjoying it, or noticing you're able to convey your algorithms much more efficiently and quickly in Fortran, then by all means.
 
Old 10-07-2007, 08:34 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,149

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Well, on Linux systems, FORTRAN is usually compiled by the GNU "gcc" compiler. Input file to "gcc" normally specifies the language of the file by a file suffix (.c for C code; .cpp or .c++ for C++ code; .F for fixed-format FORTRAN code; .F90 or .F95 for free-format FORTRAN, .ads or .adb for ADA code; .s for assembly code), and is, I believe (but have not verified), "compiled" by translation to a common "meta" language which is then compile for the target processor. If that supposition is true, there may be, at best, minor differences in efficiency in the language you choose to use.

Of course, the "best" language to use for numeric computations is assembly, and a common strategy when trying to get the most efficient code for a numerical computation is to stop the compilation after the assembly language is generated (from whatever language you choose to use), and to then "tweak" that code by hand.
 
Old 10-08-2007, 12:23 AM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

One factor in your decision might be your field. Many scientific codes are written in Fortran. Many are legacy codes, but there are many that are newly written. If you're going to work in chemistry, physics, engineering, astronomy, meteorology, etc., then I think Fortran would be a requirement.

Fortran makes it easier to write solutions for problems involving mathematical relationships. It is not as good as other languages for pushing characters around.

A few years ago I worked on a large Fortran code, more than 1000 modules with 100+K lines. I was porting it from a Cray to a Linux PC. There are many codes of that size, and many are larger. There are free implementations of Fortran, but the client purchased a license for a commercial Fortran (PGI).

You can compare times of languages to solve about 20 example problems at http://shootout.alioth.debian.org/

Best wishes ... cheers, makyo
 
Old 10-08-2007, 02:31 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I know this is off topic but indienick's program to find the primes that took over five hours, makes me think that there was something wrong with the design. If I remember correctly the sieve just removes the product of each number hence for 2 you remove 4, 6, 8, 10 and then for 3 you remove 6, 9, 12, 15 etc. I threw this together (C++ & Qt libraries) with no thought to making it efficient and it ran in just under 2 seconds for a million numbers.

My point the algorithm design is just as important as the language?
 
Old 10-08-2007, 10:31 AM   #6
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Quote:
Originally Posted by graemef View Post
I know this is off topic but indienick's program to find the primes that took over five hours, makes me think that there was something wrong with the design. If I remember correctly the sieve just removes the product of each number hence for 2 you remove 4, 6, 8, 10 and then for 3 you remove 6, 9, 12, 15 etc. I threw this together (C++ & Qt libraries) with no thought to making it efficient and it ran in just under 2 seconds for a million numbers.

My point the algorithm design is just as important as the language?
You're absolutely right. I kept trying to re-vamp the Java program to make it faster, but I kept hitting a block - collection types. While it may be argued that I should have just used and int array of X length (determined by the limit argument to the program), I found it easier just to use a java.util.ArrayList<Integer> class. Any attempt I had to make it more efficient lead to really messed up output. No more deterring from the topic though.

Moral of this story: Don't use Java for numerical computation; it's meant for network-based applications, and that's about it.
Quote:
"...'scuse me, could you turn down your heap? Thanks."
 
Old 10-08-2007, 05:00 PM   #7
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Quote:
Originally Posted by PTrenholme View Post
Of course, the "best" language to use for numeric computations is assembly, and a common strategy when trying to get the most efficient code for a numerical computation is to stop the compilation after the assembly language is generated (from whatever language you choose to use), and to then "tweak" that code by hand.
Hand tweaking these days can make execution time worser. Compiler may use optimization e.g. for Intel NetBurst. Disassembled code may look illogical for human, but computer executes it faster because it takes into account how many cycles each instruction operates and distributes thema accordingly. It's sad , that gcc is the worst compiler in this (optimization) aspect (probably because it supports so many architectures).

Quote:
Originally Posted by Indienick
Moral of this story: Don't use Java for numerical computation; it's meant for network-based applications, and that's about it.
Indienick, I disagree. Java is good for basic stuff (apps, maths, etc, dunno how you've got 5 minutes ), but really not for networking (I mean working with hardware, not only with provided libs). Not a good example, but still: traffic controlling & malformed packets.

Last edited by Alien_Hominid; 10-08-2007 at 05:02 PM.
 
Old 10-08-2007, 05:59 PM   #8
andrews-mark
Member
 
Registered: Feb 2007
Location: London
Distribution: debian
Posts: 108

Original Poster
Rep: Reputation: 15
many thanks for all the discussion. It has been very informative to me.

It seems that as a general conclusion there is no "one true way" even for some specific programming problem like numerical computing. That makes sense and it is good to hear.

Even if I never use it extensively, I think I will try to learn some fortran. After that I might even try to learn lisp

-mark
 
Old 10-09-2007, 07:30 AM   #9
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Hee hee! Welcome to the dark side, we have cookies!
 
  


Reply

Tags
fortran


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortran 77: is it worth getting into it? frankie_DJ Programming 8 02-03-2006 11:02 AM
Python - worth learning? vharishankar Programming 39 07-08-2005 02:38 AM
Is Visual Basic worth learning? titanium_geek Programming 20 07-07-2005 09:58 AM
Is it really worth learning vi at this point? Tyir Linux - General 8 02-24-2004 12:51 AM
Is scripting worth learning ChimpFace9000 Linux - General 3 07-05-2001 04:02 AM


All times are GMT -5. The time now is 06:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration