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

时间:2018-06-12 19:21:43

标签: fortran intel-fortran fortran-coarrays

考虑以下代码,尝试创建包含可变长度可分配字符类型数组的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

Intel的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 个答案:

答案 0 :(得分: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临时副本。