Dear Wolfgang,

Yes you are right on that point. Perhaps a dedicated more efficient code can 
always be written, if given enough time. I do appreciate the point.

My question was based on my personal experience some time back. I had written a 
DEM (discrete element method) code using C++ and Blitz++. The Blitz++ website 
gives benchmark results for comparison between C++ programs written using Blitz 
and those written with Fortran, and they compare pretty well. However, on 
execution of my code I observed that it loaded the PC hardware in a big 
way!...in fact the PC noise increased drastically when I executed my programm.

Following this, I "translated" my C++ program into FORTRAN90 i.e. each of the 
C++ statements (with Blitz for matrix handling) was converted to FORTRAN90 
statement, line-by-line. On execution, I was surprised to see the PC to run 
without a noise!.....and the code also ran faster!

Since Blitz is a well developed library written by a computer science expert, I 
believe the difference in performance of the C++ and Fortran program was in the 
way the compiler transformed the high level code to lower level. The FORTRAN 
compiler assumes that the user is not a computer engineer but C++ is meant for 
use by computer engineers.

I also read somewhere that features like inheritance, polymorphism, etc of 
classes are the primary reasons why C++ has more overheads than a FORTRAN 
system, and apparently this is reason why these features are yet to be 
introduced in FORTRAN; they wanted to introduce only those features of object 
oriented programming into FORTRAN that did not compromise its 
efficiency......but then there are lots of sides to this argument.....

Regards
Abhishek



On Wed, 28 Apr 2010 19:52:13 +0530  wrote
>

> ....I had supposed that making use of C++, especially using features like

> templates and STL tend to make the program slow.......I wonder if any

> thought has been given to this...and if anyone has done a comparison

> between two similar codes, one written in C++ using Dealii and other using

> FORTRAN90?



I am unsure why you would think that templates and the STL would make programs 

slow -- generally, the opposite is assumed: templates are slow to compile but 

execute fast because the compiler has a lot of information. And the STL is a 

set of algorithms and data structures where a lot of people have spent a lot 

of time optimizing. They have certainly spent more time on it than we could 

ever have spent on it if we had tried to implement the corresponding 

algorithms and data structures ourselves (or than one would spend if one 

tried to implement them in F90, for example).



But by and large I find the question uninteresting. Clearly, if I had to 

write, say, a Stokes solver with a particular linear solver, a particular 

time stepping scheme, on a piecewise polygonal domain, and Q2/Q1 elements, I 

can write a code that is 20% or 30% faster than what you would get when using 

deal.II because you know the building blocks, shape functions, mappings, etc. 

But it'll take you 6 months to do so. On the other hand, when using deal.II, 

I can do it in 1 month. 



In other words, which approach is better really depends on your metrics: If 

your goal is to get the absolute maximal efficiency and you have a lot of 

time to spare, write a code in Fortran 77. For everyone else, you are most 

likely better off using what's there in a library like deal.II. 



This all, by the way, does not mean that we don't care about speed: We've 

spend a lot of effort profiling the library and working on the hot spots to 

make codes fast.



As for concrete comparisons with other codes: That boils down to the same 

question. You can compare with a hand-written code for a particular 

application and deal.II is more than likely to lose in terms of speed. But 

it's going to win in terms of time to develop the code. Or you could compare 

with Fortran 90 libraries that offer the same functionality -- though, 

thinking about that, this is going to be hard: deal.II is by far the largest 

and most comprehensive finite element library available as Open Source, 

irrespective of the programming language.



W.



-------------------------------------------------------------------------

Wolfgang Bangerth        email:      [email protected]

                 www: http://www.math.tamu.edu/~bangerth/



_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii

Reply via email to