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
Verify numerical primitives #129
Comments
@dev-zero Fortran built-ins are preferable. I can only find two reason for not using the intrinsics:
For the latter point, we can use For the |
@hfp thank you very much for the details. So it is indeed something which should be done at some point. |
@dev-zero I believe it is all about picking a solution that is not awkward or bulky. Let's see:
The latter point likely needs Fypp since directives may not be expanded from FPP-macros (FPP-capabilities seem to be rather limited when compared to C). As a side-note, C99 supports _Pragma (or prior to C99 most compilers provide an intrinsic to achieve the same) which allows to place a pragma (directive in F-speak) using this built-in function (takes a string representing the directive). The latter in turn allows to write preprocessor macros that expand to a directive. Regarding Developing a collection of portable i.e., wrapped (compiler-specific) directives or attributes may be the most suitable and handy solution. It can go beyond the scope of inlining functions and also provide other primitives e.g., a directive to unroll a loop a certain number of times. |
The |
@oschuett |
Yes, most of Fortran 2008 was already supported in gfortran 4.8. So, thanks for updating the conventions. Should we then also get ride of |
I went to this issue because I'm trying to improve how we evaluate the norms. dbcsr/src/ops/dbcsr_operations.F Lines 2125 to 2130 in d03f22f
norm2 since this is a "distribute" norm of the entire matrix (see the mp_sum). As far as I can see, the only place where we do a local norm is here dbcsr/src/mm/dbcsr_mm_common.F Line 603 in 34d5165
However, I did a test and found that the norm is slower than the current optimized code, so I would prefer to leave it as it is. |
@alazzaro thanks for looking into this. If it is ok at this point to not check for under- or overflow, then yes. |
I'm doing some other replacements, see 021482d. Another one is almost done... |
Out of interest I was looking into the code of CP2K to check how the L2-norm of vectors is calculated.
I got the 3 equivalent forms
sqrt(x(1)*x(1) + ...)
,sqrt(x(1)**2 + ...
andsqrt(dot_product(x,x))
but not many usages of the F2008 built-innorm2
.Being curious I looked at the machine code a typical compiler generates (see https://godbolt.org/z/c5H1Ih for a comparison of the different variants) and noticed that the built-in
norm2
is much more elaborate.Not being an expert on assembler my guess is that this is the implementation of the standard-optional
It is recommended that the processor compute the result without undue overflow or underflow.
(see 13.7.123 of the Fortran standard).A quick search in the DBCSR source code led me to the following (and it is likely not the only place):
dbcsr/src/ops/dbcsr_operations.F
Lines 2125 to 2130 in d03f22f
which seems to me a rather careless way on how to calculate the norm, given that compilers take more care when calculating the norm via an intrinsic and after a quick look into https://www.springer.com/us/book/9780817647056
Am I missing something here?
@hfp maybe you could share some insight?
The text was updated successfully, but these errors were encountered: