This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Online fortran tutorials


--- Daniel Franke <franke.daniel@gmail.com> wrote:
> On Thursday 17 January 2008 18:55:19 Ted Byers
> wrote:
> > But I don't know even if there is a fortran
> equivalent 
> > to the templates I love in C++.  
> 
> As far as I can tell, up to F2003, there isn't.
> However, one can do generic 
> programming of some sort. Have a look at the FLIBS
> [1] project of Arjen 
> Markus for examples.
> 
Thanks Daniel.  Good to know.

But templates are not just for generic programming,
although that was the origincal intent.  For example,
using template metaprogramming, I can either
completely eliminate nested loops, or partially unrol
them based on a templated policy or traits class,
including complete elimination of temporaries.  For an
example, refer to chapter 18 of C++ Templates by David
Vandevoorde and Nicolai Josuttis (an outstanding book
BTW).  And I can take it a few steps further with type
units checking with virtually no additional run time
cost (so it becomes impossible to get a velocity by
adding a mass and an acceleration ;-).

Function object composition allows one to reduce the
number of function calls.  Of course, one can't go
below the functions in the standard library, if one is
using them, but potentially complicate vector fields
can be computed more efficiently with strategic use of
a combination of metaprogramming techniques for loop
unrolling, temporary elimination, function
composition, &c.  You wouldn't believe the
opportunities for automated optimization that arise
through understanding metaprogramming.

NB: all my template metaprogramming code compiles
cleanly using GCC, so I have to start wondering about
the options for mixed language programming, or
figuring out how to obtain comparable benefits using
something, of which I am unaware, in fortran.

Thanks again

Ted


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]