Fortran可分配内存的内存表示

Fortran可分配内存的内存表示,fortran,allocatable-array,Fortran,Allocatable Array,我想知道什么是fortran可分配数组的内部内存表示形式 我理解这比原始指针要复杂一些,因为形状和等级也必须存储 我还认为这取决于实现,因为我在中找不到信息 但是,我想知道使用什么样的结构来表示可分配数组(即使只针对一个编译器) 我知道这个问题有点广泛,但如果您能提供帮助,我们将不胜感激 可分配数组、指针数组以及假定的形状数组参数使用数组描述符(也称为dope vector)处理 任何编译器都可以有自己的数组描述符结构。可以在编译器手册中找到它。但是描述符有一种标准格式,用于与C(以及可能与C通

我想知道什么是fortran可分配数组的内部内存表示形式

我理解这比原始指针要复杂一些,因为形状和等级也必须存储

我还认为这取决于实现,因为我在中找不到信息

但是,我想知道使用什么样的结构来表示可分配数组(即使只针对一个编译器)


我知道这个问题有点广泛,但如果您能提供帮助,我们将不胜感激

可分配数组、指针数组以及假定的形状数组参数使用数组描述符(也称为dope vector)处理

任何编译器都可以有自己的数组描述符结构。可以在编译器手册中找到它。但是描述符有一种标准格式,用于与C(以及可能与C通信的Fortran以外的其他软件)通信

编译器可能不会在内部使用此标准描述符,但可以。如果它也在内部使用,则编译器在调用C-可互操作过程时不必准备新的描述符。例如,gfortran计划支持此标准描述符

本机阵列描述符的一个示例与C-可互操作描述符不同,由Intel在中介绍

关于Fortran与C的进一步互操作性的技术规范ISO/IEC TS 29113:2012定义了C-可互操作数组参数的数组描述符的结构,该规范将成为Fortran 2015的一部分

在C头文件
ISO_Fortran_binding.h
中定义了一个C结构,该结构由Fortran描述符(假定形状、指针或可分配)定义

如下所示(从中,某些细节可能是特定于编译器的):

引用的
CFI\u
类型也在
ISO\u Fortran\u binding.h
标题中定义

因此,尽管此描述符可能与编译器内部使用的描述符不完全相同,但它是一个很好的示例,说明在Fortran数组描述符中应该使用哪种类型的数据组件。


但是,请注意,gfortran是一个非常常见的编译器,它还没有使用这种类型的描述符。只有一个描述符,手册中描述了当前的描述符。

Awesome。感谢新的gfortran需要一个更新的共享库,以备您尝试。该库可能不会自动显示在path上。Vladimir的响应不是co正确。CFI描述符仅与从Fortran传递到可互操作(BIND(C))例程的某些参数有关,这不一定反映Fortran编译器的内部实现。此外,规范保留了“C描述符”的某些方面依赖于实现。唯一可以依赖的是,如果C例程接收到其中一个,则布局由ISO_Fortran_binding.h中的CFI_CDESC_T指定,这在实现之间可能会有所不同。不过,如果您正在与C通信,这就是实现的方法。
CFI_cdesc_t 
    A type definition that describes a C descriptor. It contains the following structure members:

void *base_addr
    The base address of the data object that is described. For deallocated allocatable objects, base_addr is NULL. 
size_t elem_len

        For scalars: The size in bytes of the data object that is described.
        For arrays: The size in bytes of one element of the array.

int version
    The version number of the C descriptor. Currently, the only valid value is available by using the CFI_VERSION macro.
CFI_attribute_t attribute
    The attribute code of the C descriptor. For the valid values for attribute, see Table 1.
CFI_type_t type
    The type code of the C descriptor. Describes the type of the object that is described by the C descriptor. For the valid values for type, see Table 2. 

CFI_rank_t rank
    The rank of the object that is described by the C descriptor. Its value must be in the range 0 ≤ rank ≤ CFI_MAX_RANK. A value of 0 indicates that the object is a scalar. Otherwise, the object is an array.
CFI_dim_t dim[]
    An array of size rank that describes the lower bound, extent, and stride of each dimension.

There is a reserved area between rank and dim. The size of the reserved area is 12 words in 32-bit mode and 9 words in 64-bit mode.