Fortran vs C

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Fortran vs C

Postby Pradu » 24 Oct 2007, 21:28

On many websites there seem to be people saying that Fortran is a faster language than C. On others you see the contrary. I haven't learn't Fortran yet so I cannot test this claim but for those who have already: is it worth learning Fortran and is it indeed faster than C using the modern optimizing compilers available for each language on modern desktop PCs? What advantages or disadvantages would you have to writing a chess program in Fortran vs C?
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA

Re: Fortran vs C

Postby bob » 24 Oct 2007, 23:49

No difference at all. Cray Blitz was written in Fortran. I used the language from 1968 until 1994 when Crafty was started and written in C. There's not enough difference in the languages to offer any kind of speed advantage for either. C is a better language overall for this kind of stuff... Fortran is more suitable for pure math, but even then the advantage is just about zero.
User avatar
bob
 
Posts: 156
Joined: 10 May 2006, 17:59

Re: Fortran vs C

Postby Dann Corbit » 26 Oct 2007, 04:53

Advantages:
Lots of libraries for numerical operations. Might conceivably be faster for some things.

Disadvantages:
Nobody writes chess engines in Fortran, so there won't be a lot of people with experience to help you and if you post a snippet of code, probably 2/3 won't be able to read it accurately.

Also, the really good Fortran compilers are the commercial compilers (just like with C and C++). So if you want top performance, you would have to buy a compiler.
Dann Corbit
 

Re: Fortran vs C

Postby Tord Romstad » 26 Oct 2007, 09:14

bob wrote: Fortran is more suitable for pure math,

I don't agree. Fortran is suitable for some kinds of floating point computations, but this is just an extremely tiny subset of mathematics (and it is almost exclusively applied mathematics, not pure mathematics).

For pure mathematics, I use Common Lisp, Haskell, or specialized languages like Maxima and Singular.

Tord
User avatar
Tord Romstad
 
Posts: 639
Joined: 09 Oct 2004, 12:49
Location: Oslo, Norway

Re: Fortran vs C

Postby bob » 28 Oct 2007, 03:58

Tord Romstad wrote:
bob wrote: Fortran is more suitable for pure math,

I don't agree. Fortran is suitable for some kinds of floating point computations, but this is just an extremely tiny subset of mathematics (and it is almost exclusively applied mathematics, not pure mathematics).

For pure mathematics, I use Common Lisp, Haskell, or specialized languages like Maxima and Singular.

Tord


I am talking about mathematical computation, particularly (but not limited to) floating point number-crunching. C is far better for other things like system tasks, strings and such, parsing, arrays of things other than scalar variables, etc.
User avatar
bob
 
Posts: 156
Joined: 10 May 2006, 17:59

Re: Fortran vs C

Postby Tord Romstad » 28 Oct 2007, 23:52

bob wrote:I am talking about mathematical computation, particularly (but not limited to) floating point number-crunching.

Floating point number crunching has very limited usability in pure (as opposed to applied) mathematics. I've spent most of my adult life doing pure mathematics, and as far as I can remember, I haven't used floating point numbers even a single time. My mathematical computations are about integers (true integers, of course, not 32-bit or 64-bit integers), rational numbers, various finite groups and fields, polynomials, and other more exotic high-level structures. You don't find this kind of stuff in Fortran, and it is a very inconvenient language for implementing it.

Tord
User avatar
Tord Romstad
 
Posts: 639
Joined: 09 Oct 2004, 12:49
Location: Oslo, Norway

Re: Fortran vs C

Postby bob » 29 Oct 2007, 01:57

Tord Romstad wrote:
bob wrote:I am talking about mathematical computation, particularly (but not limited to) floating point number-crunching.

Floating point number crunching has very limited usability in pure (as opposed to applied) mathematics. I've spent most of my adult life doing pure mathematics, and as far as I can remember, I haven't used floating point numbers even a single time. My mathematical computations are about integers (true integers, of course, not 32-bit or 64-bit integers), rational numbers, various finite groups and fields, polynomials, and other more exotic high-level structures. You don't find this kind of stuff in Fortran, and it is a very inconvenient language for implementing it.

Tord


Tord. Did not use the term "pure mathematics" in the sense you are talking about. :) I am talking about large simulations and such that use large arrays of FP data. No symbolic-type data, just raw number crunching. That was, and is, its primary forte'... If you visit places like Los Alamos National Lab, or Lawrence Livermore National Lab, or Argonne National Lab, etc... you find 90% FORTRAN programs... BIG programs. I have personally looked at a program that does a nuclear simulation that was over 7M lines of FORTRAN... (this was at Los Alamos several years ago...)
User avatar
bob
 
Posts: 156
Joined: 10 May 2006, 17:59

Re: Fortran vs C

Postby Daniel Shawul » 30 Oct 2007, 16:04

Different experience here.As a civil engineer, I write programs which involve lots of matrix manupilations. C's handling of arrays compared to Fortran's is pathetic at best:)
And also there is vast amount of free numeric libraries written in Fortran. These libraries are highly optimized and rewriting is usually a waste of time. Recently i needed to calculate eigen vectors of a matrix for calculating mode shapes of a vibrating object, and then tried to write my own version of it. It was simply very slow and incomplete.
But I agree for high level programming , OOP c is much better. What I do now is write GUI staff with MFC, and Fortran as the real 'engine' to do whatever numver crunching i need.

A random idea as to Fortran's use to chess: Use of fortran arrays instead of a collection of bitboards, anyone? :wink:
User avatar
Daniel Shawul
 
Posts: 366
Joined: 28 Sep 2004, 09:33
Location: Ethiopia

Re: Fortran vs C

Postby bob » 30 Oct 2007, 18:00

Daniel Shawul wrote:Different experience here.As a civil engineer, I write programs which involve lots of matrix manupilations. C's handling of arrays compared to Fortran's is pathetic at best:)
And also there is vast amount of free numeric libraries written in Fortran. These libraries are highly optimized and rewriting is usually a waste of time. Recently i needed to calculate eigen vectors of a matrix for calculating mode shapes of a vibrating object, and then tried to write my own version of it. It was simply very slow and incomplete.
But I agree for high level programming , OOP c is much better. What I do now is write GUI staff with MFC, and Fortran as the real 'engine' to do whatever numver crunching i need.

A random idea as to Fortran's use to chess: Use of fortran arrays instead of a collection of bitboards, anyone? :wink:


That's what NuChess (Dave Slate's last program) did. An array of bitboards for each type of piece, rather than individual scalar values...
User avatar
bob
 
Posts: 156
Joined: 10 May 2006, 17:59

Re: Fortran vs C

Postby Dann Corbit » 31 Oct 2007, 00:12

Tord Romstad wrote:
bob wrote:I am talking about mathematical computation, particularly (but not limited to) floating point number-crunching.

Floating point number crunching has very limited usability in pure (as opposed to applied) mathematics. I've spent most of my adult life doing pure mathematics, and as far as I can remember, I haven't used floating point numbers even a single time. My mathematical computations are about integers (true integers, of course, not 32-bit or 64-bit integers), rational numbers, various finite groups and fields, polynomials, and other more exotic high-level structures. You don't find this kind of stuff in Fortran, and it is a very inconvenient language for implementing it.

Tord


Of course, with modern Fortran compilers, you can create classes for things like rational numbers, arbitrary precision integers, etc.
Here is a sample for Fortran 90 that creates a rational number type:
http://www.owlnet.rice.edu/~mech517/F90 ... op_f90.pdf

Of course, it is much nicer to have it built in.
Dann Corbit
 

Re: Fortran vs C

Postby Dann Corbit » 31 Oct 2007, 00:17

Daniel Shawul wrote:Different experience here.As a civil engineer, I write programs which involve lots of matrix manupilations. C's handling of arrays compared to Fortran's is pathetic at best:)
And also there is vast amount of free numeric libraries written in Fortran. These libraries are highly optimized and rewriting is usually a waste of time. Recently i needed to calculate eigen vectors of a matrix for calculating mode shapes of a vibrating object, and then tried to write my own version of it. It was simply very slow and incomplete.
But I agree for high level programming , OOP c is much better. What I do now is write GUI staff with MFC, and Fortran as the real 'engine' to do whatever numver crunching i need.

A random idea as to Fortran's use to chess: Use of fortran arrays instead of a collection of bitboards, anyone? :wink:


There are some advantages to using C++ for numerical work. Templates, in particular, allow for a sort of generic programming that makes it easy for the compiler to inline work.
There are several sites dedicated to using C++ for numerical work.

http://www.extreme.indiana.edu/hpc++/
http://www.oonumerics.org/oon/
http://www.crpc.rice.edu/newsletters/ap ... .hpcc.html

A web search for "High performance C++" will turn up plenty more.
Dann Corbit
 


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 11 guests

cron