首页 文章

Coarray派生类型的可分配字符组件的可分配向量

提问于
浏览
2

请考虑以下代码,该代码尝试创建包含可变长度可分配字符类型数组的coarray派生类型 .

program testCoarrayJaggedArray

implicit none

integer :: i
type                                :: CharVec_type
    character(:), allocatable       :: record
end type

type                                :: List_type
    type(CharVec_type), allocatable :: Item(:)
end type

type(List_type)                     :: List[*]

if (this_image()==1) then
    allocate( List%Item(num_images()) )
    do i = 1, num_images()
        allocate( character(63) :: List%Item(i)%record )
        write(List%Item(i)%record,*) i
        List%Item(i)%record = "King" // trim(adjustl(List%Item(i)%record))
    end do
    sync images(*)
else
    sync images(1)
    allocate( List%Item( size(List[1]%Item(:)) ) )
    do i = 1, size(List%Item(:))
        allocate( character( len(List[1]%Item(i)%record) ) :: List%Item(i)%record )
        List%Item(i)%record = List[1]%Item(i)%record
        write(*,*) this_image(), List%Item(i)%record
    end do
end if

end program testCoarrayJaggedArray

英特尔的ifort 2018在调试模式下,共享内存coarray,抱怨这段代码的几个方面 . 这是第一个:

ifort /debug /Qcoarray=shared /standard-semantics /traceback /gen-interfaces /check /fpe:0 main.f90 -o run.exe
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.2.185 Build 20180210
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

main.f90(30): error #6457: This derived type name has not been declared.   [CHARACTER]
        allocate( character( len(List[1]%Item(i)%record) ) :: List%Item(i)%record )
------------------^
main.f90(30): error #8235: If type specification appears, the type and kind type parameters of each object being allocated must be the same as type and kind type parameters of the type specification.   [RECORD]
        allocate( character( len(List[1]%Item(i)%record) ) :: List%Item(i)%record )
---------------------------------------------------------------------------^
compilation aborted for main.f90 (code 1)

这段代码是非标准的Fortran吗?特别是使用第一个图像上相应字符的长度分配字符类型的行:

allocate( character( len(List[1]%Item(i)%record) ) :: List%Item(i)%record )

1 回答

  • 1

    无论程序的一致性如何,第一条错误消息都是乱码: character 不是派生类型的有效名称 . 至少,这应该作为执行质量问题报告给英特尔支持 .

    现在,代码是否符合要求?我不会回答这个问题,而是看下面的程序:

    integer :: i[*]
    character(:), allocatable :: x
    
    i=1
    allocate(character(i[this_image()]) :: x)
    
    end
    

    当我用ifort 18.0.2编译时

    test.f90(5): error #6457: This derived type name has not been declared.   [CHARACTER]
    allocate(character(i[this_image()]) :: x)
    ---------^
    test.f90(5): error #8235: If type specification appears, the type and kind type parameters of each object being allocated must be the same as type and kind type parameters of the type specification.   [X]
    allocate(character(i[this_image()]) :: x)
    ---------------------------------------^
    compilation aborted for test.f90 (code 1)
    

    让我们来看看这个程序应该发生什么 .

    我们可能都同意唯一有争议的行是分配语句,并且唯一有用的部分是(再次)类型规范的长度类型参数 . 那么 i[this_image()] 是一个有效的类型参数吗?

    它是一个标量整数表达式并且已定义 . 我们只需要确定是否存在违反的任何其他限制 . Fortran 2008中没有 .

    编译器不应拒绝此程序 .

    作为问题程序的解决方法:创建要在分配语句中使用的长度表达式的非coarray临时副本 .

相关问题