Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template programming #13

Open
wadudmiah opened this issue Jul 26, 2017 · 12 comments
Open

Template programming #13

wadudmiah opened this issue Jul 26, 2017 · 12 comments

Comments

@wadudmiah
Copy link

wadudmiah commented Jul 26, 2017

edit by @szaghi

Discussion about Template programming started into issue 2 and continued here for the sake of clarity.

@zbeekman zbeekman marked this as a duplicate of #14 Jul 26, 2017
@zbeekman
Copy link
Member

I was opening the same issue right as you posted this one. Here is what I had to say:

This is a place to discuss templating as a new/additional Fortran language feature, rather than issue #2, which is a more procedural discussion about how to adequately document proposed language features.

I personally think this has been hashed out many times in the past, and that there are some very serious drawbacks to the notion of templating, including combinatorial explosion of generated code, incomprehensible error messages, and hindering compiler optimizations, to name a few. I think there are better alternative approaches to generic programming, but wanted to open this issue since it was brought up by @wadudmiah on #2 and I am certainly open to hearing other peoples opinions, suggestions, concerns etc.

@szaghi
Copy link
Member

szaghi commented Jul 26, 2017

For the sake of convenience, I repeat here the comments of @wadudmiah and @tclune contained into issue 2

@wadudmiah said

How would you vectorise templated operations? From what I understand, widths of data types can only be determined at runtime or is this not the case? If templated operations can be vectorised, then this will definitely be a useful feature to have. A templated BLAS library could be written!

@tclune commented

With regard to templates in the language ... types would not be determined at run time. Everything must be resolved by the time the executable is created. I believe that the approach in C++, is that a great deal of compilation is actually deferred until link time when the needed types are known.

My experience about templating is nearly zero, thus I cannot add any useful comments. Anyhow, I recently read about a Van Snyder's proposal about parametrized module that sounds very very interesting for achieving generic programming.

My best regards.

@szaghi szaghi changed the title Template programming (see ticket #2 for background) Template programming Jul 26, 2017
@wadudmiah
Copy link
Author

@zbeekman I totally agree that there are issues with templated programming and you have listed some good points. With regards to compiler optimisations, I didn't think the compiler will be able to vectorise operations unless it re-compiles the code to determine the width of the data types.

@cmacmackin
Copy link

I haven't used C++ so I don't know for certain, but I think templating is a purely compile-time feature. The compiler will only create versions of types/procedures needed at compile time. For libraries, this means that you must either specify in advance which types you want to pass to your generics or you put all template code in the header files. The compiler will always know what types a given routine will work with, so it shouldn't present any problem to compiling or optimisation. However, it can lead to very long compile times.

I'm interested to know what @zbeekman means in terms of better approaches to generic programming. I'm not aware of any approaches other than something like templates. Modern compilers can certainly work to minimise some of the concerns about how long it takes to compile. The nim language offers some superb generic programming features (including ways to constrain types) which, among other things, help to ensure better error messages. Its compiler is very fast. However, that compiler manages things like dependency resolution to help with this and I don't think all of the same tricks would be possible with GCC.

@wadudmiah
Copy link
Author

I don't think the Fortran standard would dictate whether this is a compile time feature or not. This would be left to the compiler/runtime system.

@cmacmackin
Copy link

cmacmackin commented Jul 26, 2017 via email

@wadudmiah
Copy link
Author

I guess we will be at the mercy of compiler vendors then :-( I'm sure the Intel compiler will ensure it is resolved at compile time as they are very keen on vectorisation - not sure about gfortran.

@cmacmackin
Copy link

cmacmackin commented Jul 26, 2017 via email

@zbeekman
Copy link
Member

zbeekman commented Jul 26, 2017 via email

@milancurcic
Copy link

When I was implementing the boilerplate nightmare of specific procedures in functional-fortran, I was very close to writing a template preprocessor/transpiler. I was good enough with vim to do this manually so it didn't get to that.

Useful things like templates or anonymous functions could be implemented as a preprocessor/transpiler.

@zbeekman
Copy link
Member

zbeekman commented Jul 26, 2017 via email

@szaghi
Copy link
Member

szaghi commented Jul 26, 2017

@zbeekman

So, IMO, you need some form of templating in the language, or some other means to achieve similar functionality added to the standard or at least some viable alternative to be standardize, i.e., a preprocessor.

What about the parametrized module proposed by Van Snyder? I do not know its details, but it sounds promising...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants