Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran-变量的使用_Fortran - Fatal编程技术网

Fortran-变量的使用

Fortran-变量的使用,fortran,Fortran,编译后,使用额外变量引用数组的某个部分与持续索引它在执行速度/效率方面有什么区别吗?例如: ... some code that defines/populates "array" here ... item3 = array(3) subroutine1(item3, ...) ... subroutine2(item3, ...) ... some equation using item3 ... subroutine3(item3, ...) ... etc x = b / c y =

编译后,使用额外变量引用数组的某个部分与持续索引它在执行速度/效率方面有什么区别吗?例如:

... some code that defines/populates "array" here ...
item3 = array(3)
subroutine1(item3, ...)
...
subroutine2(item3, ...)
...
some equation using item3
...
subroutine3(item3, ...)
... etc
x = b / c
y = x + 1  ! This is the only use of x

... some code that defines/populates "array" here ...
subroutine1(array(3), ...)
...
subroutine2(array(3), ...)
...
some equation using array(3)
...
subroutine3(array(3), ...)
... etc
另一个例子可能是创建一个可以跳过的变量。例如:

... some code that defines/populates "array" here ...
item3 = array(3)
subroutine1(item3, ...)
...
subroutine2(item3, ...)
...
some equation using item3
...
subroutine3(item3, ...)
... etc
x = b / c
y = x + 1  ! This is the only use of x
vs


在编译时,它们是等效的,还是第一个会因为创建变量“x”而变慢?如果你多次需要“x”的值,那么我假设第一次会更快,因为它可以避免多次除法。但我不确定是否只使用1或2次。

这是非常依赖于编译器的。根据优化选项和代码生成的不同,它的效率可能会有所不同。如果有任何差异,它可能会非常小-以最清晰的方式编写代码。优化编译器可以处理类似的内容,请编写清晰的代码。