[Numpy-discussion] Fortran was dead ... [was Re: rewriting NumPy code in C or C++ or similar]
Matthieu Brucher
matthieu.brucher@gmail....
Mon Mar 14 17:10:13 CDT 2011
Hi,
Intel Fortran is an excellent Fortran compiler. Why is Fortran still better
than C and C++?
- some rules are different, like arrays passed to functions are ALWAYS
supposed to be independent in Fortran, whereas in C, you have to add a
restrict keyword
- due to the last fact, Fortran is a language where its compiler could do
more work (vectorization, autoparallelization...)
- Fortran 95 has an excellent array support, which is not currently
available in C/C++ (perhaps with ArBB?)
Nevertheless, when you know C++ correctly, when you want to do something
really efficient, you don't use Fortran. You can be as efficient as in C++,
and you can do fancy stuff (I/O, network...). Class and templates are also
better supported in C++.
Matthieu
2011/3/14 Sebastian Haase <seb.haase@gmail.com>
> On Mon, Mar 14, 2011 at 9:24 PM, Ondrej Certik <ondrej@certik.cz> wrote:
> > Hi Sturla,
> >
> > On Tue, Mar 8, 2011 at 6:25 AM, Sturla Molden <sturla@molden.no> wrote:
> >> Den 08.03.2011 05:05, skrev Dan Halbert:
> >>> Thanks, that's a good suggestion. I have not written Fortran since
> 1971,
> >>> but it's come a long way. I was a little worried about the row-major vs
> >>> column-major issue, but perhaps that can be handled just by remembering
> >>> to reverse the subscript order between C and Fortran.
> >>
> >> In practice this is not a problem. Most numerical libraries for C assume
> >> Fortran-ordering, even OpenGL assumes Fortran-ordering. People program
> >> MEX files for Matlab in C all the time. Fortran-ordering is assumed in
> >> MEX files too.
> >>
> >> In ANSI C, array bounds must be known at compile time, so a Fortran
> >> routine with the interface
> >>
> >> subroutine foobar( lda, A )
> >> integer lda
> >> double precision A(lda,*)
> >> end subroutine
> >>
> >> will usually be written like
> >>
> >> void foobar( int lda, double A[]);
> >>
> >> in C, ignoring different calling convention for lda.
> >>
> >> Now we would index A(row,col) in Fortran and A[row + col*lda] in C. Is
> >> that too difficult to remember?
> >>
> >> In ANSI C the issue actually only arises with small "array of arrays"
> >> having static shape, or convoluted contructs like "pointer to an array
> >> of pointers to arrays". Just avoid those and stay with 1D arrays in C --
> >> do the 1D to 2D mapping in you mind.
> >>
> >> In C99 arrays are allowed to have dynamic size, which mean we can do
> >>
> >> void foobar( int lda, double *pA )
> >> {
> >> typedef double row_t [lda];
> >> vector_t *A = (vector_t*)((void*)&pA[0]);
> >>
> >> Here we must index A[k][i] to match A(i,k) in Fortran. I still have not
> >> seen anyone use C99 like this, so I think it is merely theoretical.
> >>
> >> Chances are if you know how to do this with C99, you also know how to
> >> get the subscripts right. If you are afraid to forget "to reverse the
> >> subscript order between C and Fortran", it just tells me you don't
> >> really know what you are doing when using C, and should probably use
> >> something else.
> >>
> >> Why not Cython? It has "native support" for NumPy arrays.
> >>
> >> Personally I prefer Fortran 95, but that is merely a matter of taste.
> >
> > +1 to all that you wrote about Fortran. I am pretty much switching to
> > it from C/C++ for all my numerical work, and then I use Cython to call
> > it from Python, as well as cmake for the build system.
> >
> > Ondrej
>
>
> Hi,
> this is quite amazing...
> Sturla has been writing so much about Fortran recently, and Ondrej now
> says he has done the move from C/C++ to Fortran -- I thought Fortran
> was dead ... !? ;-)
> What am I missing here ?
> Apparently (from what I was able to read-up so far) there is a BIG
> difference between FORTRAN 77 and F95.
> But isn't gcc or gfortran still only supporting F77 ?
> How about IntelCC's Fortran ? Is that superior?
> Do you guys have any info / blogs / docs where one could get an
> up-to-date picture?
> Like:
> 1. How about debugging - does gdb work or is there somthing better ?
> 2. How is the move of the F77 community to F95 in general ? How many
> people / projects are switching.
> 3. Or is the move rather going like Fortran 77 -> C -> Python ->
> Fortran 95 !? ;-)
>
> Thanks,
> Sebastian Haase
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110314/f761bfdf/attachment.html
More information about the NumPy-Discussion
mailing list