admin管理员组文章数量:1201413
Consider the following minimal example:
subroutine f(x,a,b,c)
integer::x,i,j,k
integer,optional::a,b,c
! depending on present arguments, some expressions and variables are redundant
i=42*x
j=137*x
k=142857*x
! potentially more `if(present(...))...` statements in the procedure
if(present(a))a=i*x
if(present(b))b=j*x
if(present(c))c=k*x
end
Will a Fortran compiler (GNU or Intel) with the -O3
compiler option generate 8 (2^3) specialized versions of this subroutine depending on the list of present arguments and eliminate dead code (redundant expressions) for better performance? Or will it generate only one subroutine with conditional statements? The second case can be significantly slower for larger procedures with a lot of if(present(...))...
statements (e.g. in loops) and potentially redundant expressions. However, the first case will increase the size of the compiled binary file. And is there a simple way to check, which choice a compiler makes?
(If specialized versions are generated and dead code is eliminated, I consider using this behavior to improve the readability of the code that generates overloaded versions of a large procedure with different lists of arguments and currently uses conditional preprocessor statements.)
本文标签: compiler optimizationSpecialized versions of a Fortran procedureStack Overflow
版权声明:本文标题:compiler optimization - Specialized versions of a Fortran procedure - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738631842a2103792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论