views:

554

answers:

6

Hi,as an engineer I currently use C to write programs dealing with numerical methods. I like C as it's very fast. I don't want to move to C++ and I have been reading a bit about Ada which has some very good sides. I believe that much of the software in big industries have been or more correctly were written in Ada.

I would like to know how C compares with Ada. Is Ada fast as C? I understand that no language is perfect but I would like to know if Ada was designed for scientific computing.

Thanks a lot...

+1  A: 

Ada is used most in the defense and aerospace industry, not in "big industry" in general. Its main aim was safety, so it is not specifically targeted for scientific computation.

Péter Török
Thanks. But the defense and aerospace industry do much numerical computations, no?
yCalleecharan
Dunno, have never worked there. But in my view safety and speed are to a large extent contrary aims. Safety means a lot of extra checks, even during runtime, which obviously hinders performance.
Péter Török
I understand what you mean. I wait and see what others have to say about Ada.
yCalleecharan
Actually, its main aim was to be a general-purpose programming language so that the DoD could quit having to create and support new ones all the time. Because of that it had all kinds of other requirements to support things like systems programming, numerical programming, real-time programming, etc. Safety is just one of the things it happened to end up doing well that most other languages still don't bother with.
T.E.D.
+6  A: 

Choose Fortran. Fortran compilers can perform much better optimization and parallelization than C compilers. The most important data structure for scientific and engineering computations is array. And the Fortran language has true arrays. And many useful array-related features: intrinsic and user defined ELEMENTAL functions, some very useful constructs (WHERE, FORALL) and many more.

Modern Fortran is powerful language. By "modern" I mean current (Fortran 2003) language standard. Comparing to C++ (and Ada) there is no support for generic programming only.

Also the very common practice is to mix Fortran and Python. Take a look at this Why we use Fortran and Python blog entry. Fortran for intensive numerical tasks, Python for GUI, testing, build automation (SCons), adding support for generic programming (Forpedo, PyF95++), ... Also take a look at NumPy. It contains F2PY - Fortran to Python interface generator.

kemiisto
Thanks for your comments. I have never used Fortran but it seems archaic now for one to learn Fortran in the 21st century.
yCalleecharan
FORTRAN appeared in 1957, Ada in 1983. If ones start criticize Ada citing Dijkstra Ada fans will argue that early Ada and modern Ada are different languages. But the situation with FORTRAN is the same. Starting from so-called Fortran-90 standard committee even changed the name of the language ("decapitalized" it) to reflect enormous changes in the language. Starting from Fortran-2003 the language has full OOP support... Read this: http://stackoverflow.com/questions/1335703/fortran-as-a-good-choice
kemiisto
Small advice: don't criticize things which you even never see and used. When ones make a choice it would be nice to know options. Your problem is that you don't actually know them. So you need to believe. And believe me or actualli Wikipedia that "Fortran is the primary language for some of the most intensive supercomputing tasks, such as weather and climate modeling, computational fluid dynamics, computational chemistry, computational economics, plant breeding and computational physics." (c) http://en.wikipedia.org/wiki/Fortran#Legacy
kemiisto
Thanks for your comments and for reminding me not to judge blindly what I don't know. I do have a false image of Fortran.
yCalleecharan
M. S. B.
One problem with Fortran is the lack of free multitude of free compilers as compared to C. I may be wrong though. Since I work a lot with arrays, I would prefer to take a look at ADA that has inherent safety checks as compared to C.
yCalleecharan
@yCalleecharan: of course, you're aware that that bounds checking comes at a cost, right?
SamB
I can get good C++ compilers for the cost of a download. I can get what as far as I know is a good Ada compiler in the same way. Is there a good Fortran 2003 compiler available for free (or, better, as Free Software)?
David Thornley
@David Thornley: gfortran. Support for the Fortran 2003 Standard: http://fortranwiki.org/fortran/show/Fortran+2003+status Benchmarks: http://www.polyhedron.com/pb05-linux-f90bench_p40html
kemiisto
+1: Actually, this is closer to right than many might think. Fortran compilers are very good at optimizing numerical programming for two main reasons: 1) They made a whole raft of language design decisions that make things much easier on the optimizer than C's design is. 2) Fortran users care about numerical programming more than C's users, so the compiler writers put much more effort into it. Ada actually goes Fortran one better on advantage one, but it is tough to compete with advantage two.
T.E.D.
Thanks for all the inputs here. Maybe at times, speed is not the key. Getting accurate results without trying to do all checking on array bounds by oneself can be helpful with a language like Ada.
yCalleecharan
@yCalleecharan: Fortran compilers can perform array bounds checking. For example, for gfortran use -fbounds-check compile option. This feature is optional. So you can choose to perform array bounds checking in debug version, but do not waste resources in final release.
kemiisto
This is interesting to know. Fortran seems better than C for numerical computations.
yCalleecharan
Many years ago, turning on subscript checking in Fortran programs had a big run-time cost. With today's compilers and computers, I've been surprised at how small the increased run-time is for most programs. I leave subscript checking on for a lot of my programs, removing it post-debugging for only the longest running programs.Free Fortran 95 compilers: gfortran, g95, Sun Studio and for limited uses on Linux, ifort. All except Sun Studio (Solaris and Linux) are available for the popular OSes.
M. S. B.
+4  A: 

Ada lets the programmer specify what they actually want the program to do in a much more fine-grained way than C does. This makes it possible for compilers and other tools to do a lot of static code analysis to point you to problematic code areas before you even run the program. This static code analysis does not come with any run-time performance penalty, so you can get that benefit even if the generated machine code is more or less the same.

The run-time checks are different. I would expect good compilers can (through static code analysis) determine what checks can and cannot be triggered. This would allow you to write your code in such a way that value ranges are handled in a way that eleminates most of the runtime checks as well. I am not familiar with the actual state of the art in this area, though.

You can still get the benefits of the static code analysis without runtime penalties by just disabling the runtime checks. I would really benchmark things though and make sure that those few percentage points the runtime checks take are actually a problem for your application before you turn them off, though.

ndim
Thanks for your comments.
yCalleecharan
A: 

Better stick to C...


This is because C offers tight integration with the target and a being closer to assembly several optimisations can be hand-crafted to suit ur purpose.

You might be interested in this:

http://www.adaic.org/whyada/ada-vs-c/ada-vs-c.html

Which particular architecture/device are U targeting??...

CVS @ 2600Hertz

CVS-2600Hertz
"Being closer to assembly" -> very few optimizations are possible. And easy (implicit) parallelization for any low-level language is just a dream. And his "device" is probably some big computational cluster. ;-)
kemiisto
Thanks for the comments and for the link. I'm not doing embedded c programming. I'm dealing with numerical methods.
yCalleecharan
+1 I disagree with the answer, but the link offers several useful heuristics to guide the questioner.
trashgod
I agree that the link is good and very informative.
yCalleecharan
The linked article references pre-standard C++, and so completely ignores C++ vectors when discussing arrays. Moreover, it discounts some of C++'s philosophy. C++ array references are by default unchecked because it is always possible to add boundary checks when wanted, but it isn't possible to discard them when they're built in. The article is interesting in showcasing some of Ada 95's strong points, but I don't think it's particularly relevant as a comparison today.
David Thornley
@trashgod: Good link, but not enough to save the -1 from me I'm afraid. The answer is just *so* wrong. In fact, C is very poorly designed for numerical computing for exactly the reason he claims it is good. It is so low-level that the compiler has no idea what you are getting at with any line of code, so it has much more trouble optimizing.
T.E.D.
@T.E.D.: Your point is well taken and lends a valuable perspective. @David Thornley: As the editors note, the cited article is dated, but Ada is designed for long-term maintenance. In this regard, it is often easier to asses the effects of a disabled constraint than to find one that should have been present _ab initio_.
trashgod
@trashgod: The article says that Ada's better than C++ because Ada checks array references, which is to some extent true. It omits the claim that C++ is better than Ada because Ada checks array references, which is also to some extent true. It's not a bad article as to why Ada is good, but I do maintain that it's a bad comparison.
David Thornley
I think CVS-2600Hertz-wordpres is claiming that it's easier to hand-optimize C code, which is probably true, but except in very unusual circumstances that's not much of an advantage. A less explicit language can give the compiler more room to optimize in.
David Thornley
@ T.E.D why would you want the compiler to "optimise" ur code when you are able to write the exact operation that you are looking for. hmmm? care to comment T.E.D??...
CVS-2600Hertz
Yes I do. Do you honestly think every joe schmoe is *better* at assembly-level optimization than the compiler writers? On a modern processor you have to take into account things like CPU pipelines, cache archtecture, predictive branching, etc. I'll assume you *are* that good. But for us meer mortals the compiler, operating with full knoweldge of what's going on in the hardware and full benifit of the compiler author's skills, and with the eyeballs of every compiler user to help flush out bugs, is going to do so much better a job of optimization than we can do that it just isn't comparable.
T.E.D.
One other thing I should point out. There are many optimizations that you can't even do from C. For example, almost no modern C compilers acutally honor the "register" storage class (it is silently ignored). You *have* to rely on the compiler to optimize variables into registers for you. C compilers may end up doing a good job of figuring this out, but they are operating with one hand tied behind their backs, due to C's liberal attitude toward aliasing.
T.E.D.
Got ur point T.E.D :) "Why do we even try when we can get the compiler to do it" -sigh- if only the compiler could do it. Oh i wish... :(
CVS-2600Hertz
+6  A: 

Is Ada fast as C?

To the extent that this question has a meaningful answer, you might like to compare these Ada benchmarks to the corresponding programs in other languages with which you are familiar. A popular reference implementation uses the same compiler back end as several other languages, so comparable programs typically have comparable performance. Large disparities often represent different algorithms or varying safety trade-offs.

Is Ada designed for scientific computing?

Yes, Ada is used for scientific computing in a number of fields that require long-term maintenance of large-scale, safety-critical software. I especially like the strong support for type-safe generics and operator overloading.

Addendum: Several informative comments concerning other languages remind me that this Ada implementation can use the well-tested Fortran libraries blas and lapack to implement parts of its own standard library. Moreover, the compiler itself uses the popular C libraries mpfr and gmp; a binding is available for run time use.

trashgod
Thanks for your comments and links. They were helpful.
yCalleecharan
The second sentence in the first paragraph holds a very important point. If your choice is between the gcc Ada implementation and the gcc C implementation, you are going to end up with pretty much the same speed for the same algorithims. I once saw a guy get his gnat "Hello world" implementation identical **to the byte** to a gcc C version (yeah, he used C's stdio instead of Ada's standard IO facility, but he was trying to prove a point).
T.E.D.
Thanks for the comments.
yCalleecharan
+5  A: 

Well, the real answer is that no general-purpose compiled language can really be called "slower" or "faster" than another.

Some languages (such as Fortran and especially Ada) can do things to make the job of the optimizer much easier. C, on the other hand, practically went out of its way to make things tougher. For example, any C variable can be aliased at pretty much any time, so it is a lot of work to figure out when one can be safely optimized into a CPU register.

However, Ada's theoretical advantage over C doesn't mean squat if you happen to get an Ada compiler from a vendor that didn't care about optimization and your buddy got a C compiler from a vendor who put enormous effort into theirs.

You can only talk about implementations being faster, not languages. But suffice it to say that it is quite possible to produce Ada code that is faster than the C code it replaces (without tons of source-perverting hand-optimizing).

T.E.D.
Actually, while I'm not going to say whether Ada or Fortran or C is inherently faster, I will say that Intercal is almost certainly inherently slower.
David Thornley
Intercal isn't a general-purpose compiled language. It is a no-purpose inflicted language.
T.E.D.