module - 在 Fortran 90 中使用通用 block 和模块在内存方面是否存在差异

标签 module fortran fortran90 fortran-common-block

我最近在没有任何指导的情况下学习 Fortran,并尝试了不同的版本。我从 this site 找到:

Is a MODULE better than a COMMON block?

Almost always yes. The only reasons to use COMMON blocks are if you expect to use your program on a computer with only a FORTRAN 77 compiler (they still exist), or if it is very important that you control the order in which your data is stored in memory.



好吧,使用模块在语法上肯定比使用通用 block 更甜。但是在这两种情况下,内存使用和分配有什么区别?它在性能和访问速度方面也有影响吗?这个问题有意义吗?

最佳答案

M.S.B.在他的回答中有它,但在我看来并没有足够强调它。 COMMON block 中的变量完全按照 block 定义中的顺序排列在内存中。从此限制,即没有动态内存对象(可分配的,指针)可以在 COMMON block 中,紧随其后。

“序列关联”意味着您可以依靠变量的放置方式,例如,使用两个以下数组作为一个大数组。

COMMON block 在现代代码中可能没有位置,尽管它们没有被宣布为过时。

在速度方面,如果变量相同,那么访问它应该没有任何区别,无论是在模块中还是在 COMMON block 中。

关于module - 在 Fortran 90 中使用通用 block 和模块在内存方面是否存在差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23771021/

相关文章:

pointers - Fortran 指针虚拟参数

arrays - 在 Fortran 中查找两个数组的交集

javascript - 如何将 JavaScript 代码库划分为模块?

c++ - VS2017 C++ 标准库模块

module - 如何从私有(private)模块中的公共(public)函数引用私有(private)类型?

linux - 有没有办法让 Splint 或类似的静态检查器与 Linux 内核模块一起工作?

tensorflow - 如何在 Fortran 中使用神经网络(基于 Pytorch 或 Tensorflow)?

fortran - 什么是 : 'iunit' is used uninitialized in this function [-Wuninitialized]

fortran - "%"在 Fortran 中意味着什么?

fortran - 在 NetCDF 中沿无限维度写入标量变量