首页 文章

Fortran的内部内存表示可分配

提问于
浏览
3

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

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

我也猜测's implementation dependent, since I don't在Fortran 2003 standard找到信息 .

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

我知道这个问题有点广泛,但任何帮助都会非常感激 .

1 回答

  • 3

    使用数组描述符(也称为dope向量)处理可分配数组,指针数组以及假设的形状数组参数 .

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

    编译器内部可能不会使用此标准描述符,但它可以是 . 如果它也在内部使用,那么编译器在调用C可互操作过程时不必准备新的描述符 . 例如,gfortran计划支持标准描述符"preferably as native format" .

    英特尔在https://software.intel.com/en-us/node/678452描述了与C可互操作数据描述符不同的本机数组描述符的示例 .

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

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

    它看起来如下(从IBM website,某些细节可能是编译器特定的):

    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.
    

    引用的 CFI_ 类型也在 ISO_Fortran_binding.h 标头中定义 .

    So, even-though this descriptor may not be exactly the same that your compiler is using internally, it is a good example of what kind of data components one should expect in a Fortran array descriptor.

    但是,请注意gfortran(一种非常常见的编译器)尚未使用此类描述符 . 只有experimental version with the new descriptor,手册中描述了当前描述符 .

相关问题