Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
27427 Discussions

Coarray derived type of allocatable vector of allocatable character components

Valued Contributor I

Consider the following code that attempts to create a coarray derived type containing an array of variable-length allocatable character types.

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's ifort 2018 in debug mode, shared-memory coarray, complains about several aspects of this code. Here is the first one:

    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 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)


    Is this code non-standard Fortran? In particular the line that allocates a character type using the length of the corresponding character on the first image:

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


    0 Kudos
    1 Solution
    Black Belt

    The syntax appears to be confusing the compiler. I suggest you lodge a ticket.

    View solution in original post

    1 Reply
    Black Belt

    The syntax appears to be confusing the compiler. I suggest you lodge a ticket.