Article View: comp.std.c++
Article #2182F90 vs C++/C, optimization question?
From: enseeg14
Date: Fri, 13 Oct 1995 14:57
Date: Fri, 13 Oct 1995 14:57
44 lines
2408 bytes
2408 bytes
(I primarily posted this to comp.lang.c++, but the conclusion of it
make it fit to this ng -- unless I'm too ignorant about compiler
optimization....)
A question arose during a flamewar on comp.lang.fortran, about compiler
optimization.
C has always been the language where _THE PROGRAMMER_ could make his
own optimization, but this style of programming is getting deprecated
according to most C++ who basically say "rely on the compiler, optimize
only as a last minute operation". But here I have an example of what
would be very unefficient in C/C++ compared to F90:
> for (i = 0 ; i < n ; i++) {
> for (j = 0 ; j < n ; j++) {
> a[i][j] = b[i][j] * c[i] ;
> }
> }
> do j = 1,m
> do i = 1, n
> a (i,j) = b(i,j) * c(i)
> enddo
> enddo
The Fortran compiler can easy unroll the loop and take advantage of scalar
caches, and easily use vectorial registers, whereas the C compiler
can't even move the evaluation of c[i] out of the inner loop because
&c[i] could be == to &a[x][y] ............ That's the problem with
weak typin... I'm wondering if any of the "const" tweak would change
anything...
Despite I'm really disgusted by Fortran, I must concede this and
since only few compilers do really perform all the optimizations you
see in the books, I don't know they could get sthng good out of this...
So, if we're obliged to barf (see note) in this case, could there be any kind
of C++ extension -- another one! -- to imporve this?
Barf [ba:rf] 2. v. "He suggested using Fortran. We all barfed."
(From the Shokagukan dict, according to f2c.h)
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<45ld1i$m7i@cicg-communication.grenet.fr>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: enseeg14@grenet.fr () Newsgroups: comp.std.c++ Subject: F90 vs C++/C, optimization question? Date: 13 Oct 1995 14:57:10 GMT Organization: C.I.C.G. , Grenoble Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <45ld1i$m7i@cicg-communication.grenet.fr> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: cicg-calcul.grenet.fr Followups-To: comp.std.c++,comp.lang.c,comp.lang.c++ X-Newsreader: TIN [version 1.1 PL8] Content-Length: 1574 X-Lines: 40 Originator: clamage@taumet