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

Coarrays of UDTs with Allocatable components

Colin_W_1
Novice
871 Views

Does the standard allow a coarray to be a UDT type with allocatable components? From note 5.6 in the 2008 standard, the answer appears to be "yes":

A coarray is permitted to be of a derived type with pointer or allocatable components. The target of such
a pointer component is always on the same image as the pointer.

The same note appears in the 2018 standard, as note 1 in section 8.5.6.

OK, so if the component in question is a pointer component, it points to a target in the same image as the pointer. But what about when its an allocatable component? And, crucially for my work, what happens when the coarray is referenced from a different image? 

In my work I am trying to copy coarray elements between images. I find that, if the UDT does not contain allocatable components, the copy works correctly, but not when it does.

If necessary I can knock up an example to show what I mean. But I don't want to do that if my understanding of the standard is incorrect.

I am using IVF 17.0.2.187 and 19.1.0.166.

 

5 Replies
FortranFan
Honored Contributor III
871 Views

Colin W. wrote:

.. In my work I am trying to copy coarray elements between images. I find that, if the UDT does not contain allocatable components, the copy works correctly, but not when it does. ..

I am using IVF .. 19.1.0.166.

Submit a support request with Intel Online Service Center (OSC) if you're able to: https://supporttickets.intel.com/servicecenter?lang=en-US

My understanding is what you're doing is alright by the standard, especially with a component with the ALLOCATABLE attribute in a derived type and with copying data from another image in a coarray object of such a derived type.  The issue(s) you face is likely more due to an implementation matter.  Intel support can then hopefully guide you best. 

FortranFan
Honored Contributor III
871 Views

This is more an illustration of a quick check and for any other readers wanting to try out coarrays in Fortran with a derived type that has an ALLOCATABLE component:

   type :: t
      integer, allocatable :: n
   end type
   character(len=*), parameter :: fmtg = "(g0,t15,g0)"

   type(t), save :: foo
  • integer :: i if ( this_image() == 1 ) then foo%n = 42 end if sync all if ( this_image() /= 1 ) then foo%n = foo[1]%n + this_image() - 1 end if sync all if ( this_image() == 1 ) then print fmtg, "Image #", "foo%n" do i = 1, num_images() print fmtg, i, foo%n end do end if end
  • C:\Temp>ifort /standard-semantics /warn:all /stand:f18 /Qcoarray:shared /Qcoarray-num-images=8 p.f90
    Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
    Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.
    
    Microsoft (R) Incremental Linker Version 14.24.28316.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    -out:p.exe
    -subsystem:console
    p.obj
    
    C:\Temp>p.exe
    Image #       foo%n
    1             42
    2             43
    3             44
    4             45
    5             46
    6             47
    7             48
    8             49
    C:\Temp>

     

    Colin_W_1
    Novice
    871 Views
    program test
    
       type :: t
          real(8)              :: x1, x2, x3
          real(8), allocatable :: xn(:)
          integer              :: i1, i2, i3
          integer, allocatable :: in(:)
       end type
    
       type(t), save :: foo
  • if ( this_image() == 1 ) then foo%x1 = 20. foo%x2 = 30. foo%x3 = 40. foo%xn = [41., 42., 43., 44.] foo%i1 = 11 foo%i2 = 21 foo%i3 = 31 foo%in = [51, 52, 53, 54] end if sync all if ( this_image() /= 1 ) then foo = foo[1] end if sync all print *,' image ',this_image(), foo%x1, & foo%x1, & foo%x2, & foo%x3, & foo%xn, & foo%i1, & foo%i2, & foo%i3, & foo%in end
  •  

    With IVF 17.0.2.187 and for_coarray_num_images=2, the run either crashes, or gives the wrong answer for the allocatables:

    C:\prog\test\co\x64\Debug>co
      image            2   20.0000000000000        20.0000000000000
      image            1   20.0000000000000        20.0000000000000
       30.0000000000000        40.0000000000000        41.0000000000000
       42.0000000000000        43.0000000000000        44.0000000000000
              11          21          31          51          52          53
              54
       30.0000000000000        40.0000000000000       0.000000000000000E+000
      0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000
              11          21          31           0           0           0
               0
    
    C:\prog\test\co\x64\Debug>co
    forrtl: severe (157): Program Exception - access violation
    In coarray image 2
    Image              PC                Routine            Line        Source
    VCRUNTIME140D.dll  000007FEBB401330  Unknown               Unknown  Unknown
    co.exe             000000013FF61F2C  MAIN__                     26  eg.f90
    co.exe             000000013FF62A2E  Unknown               Unknown  Unknown
    co.exe             000000013FF64404  Unknown               Unknown  Unknown
    co.exe             000000013FF64317  Unknown               Unknown  Unknown
    co.exe             000000013FF641DE  Unknown               Unknown  Unknown
    co.exe             000000013FF64419  Unknown               Unknown  Unknown
    kernel32.dll       000000007718556D  Unknown               Unknown  Unknown
    ntdll.dll          00000000773E372D  Unknown               Unknown  Unknown
    
    application called MPI_Abort(comm=0x84000002, 0) - process 1
    
    C:\prog\test\co\x64\Debug>co
      image            2   20.0000000000000        20.0000000000000
      image            1   20.0000000000000        20.0000000000000
       30.0000000000000        40.0000000000000        41.0000000000000
       42.0000000000000        43.0000000000000        44.0000000000000
              11          21          31          51          52          53
              54
       30.0000000000000        40.0000000000000       3.250556697118729E-318
      0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000
              11          21          31           0           0           0
               0
    
    C:\prog\test\co\x64\Debug>co
    forrtl: severe (157): Program Exception - access violation
    In coarray image 2
    Image              PC                Routine            Line        Source
    VCRUNTIME140D.dll  000007FEBB401330  Unknown               Unknown  Unknown
    co.exe             000000013F2D1F2C  MAIN__                     26  eg.f90
    co.exe             000000013F2D2A2E  Unknown               Unknown  Unknown
    co.exe             000000013F2D4404  Unknown               Unknown  Unknown
    co.exe             000000013F2D4317  Unknown               Unknown  Unknown
    co.exe             000000013F2D41DE  Unknown               Unknown  Unknown
    co.exe             000000013F2D4419  Unknown               Unknown  Unknown
    kernel32.dll       000000007718556D  Unknown               Unknown  Unknown
    ntdll.dll          00000000773E372D  Unknown               Unknown  Unknown
    
    application called MPI_Abort(comm=0x84000002, 0) - process 1
    
    C:\prog\test\co\x64\Debug>co
    forrtl: severe (157): Program Exception - access violation
    In coarray image 2
    Image              PC                Routine            Line        Source
    VCRUNTIME140D.dll  000007FEBB791330  Unknown               Unknown  Unknown
    co.exe             000000013FED1F2C  MAIN__                     26  eg.f90
    co.exe             000000013FED2A2E  Unknown               Unknown  Unknown
    co.exe             000000013FED4404  Unknown               Unknown  Unknown
    co.exe             000000013FED4317  Unknown               Unknown  Unknown
    co.exe             000000013FED41DE  Unknown               Unknown  Unknown
    co.exe             000000013FED4419  Unknown               Unknown  Unknown
    kernel32.dll       000000007718556D  Unknown               Unknown  Unknown
    ntdll.dll          00000000773E372D  Unknown               Unknown  Unknown
    
    application called MPI_Abort(comm=0x84000002, 0) - process 1
    
    C:\prog\test\co\x64\Debug>co
      image            1   20.0000000000000        20.0000000000000
      image            2   20.0000000000000        20.0000000000000
       30.0000000000000        40.0000000000000       0.000000000000000E+000
      0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000
              11          21          31           0           0           0
               0
       30.0000000000000        40.0000000000000        41.0000000000000
       42.0000000000000        43.0000000000000        44.0000000000000
              11          21          31          51          52          53
              54
    
    C:\prog\test\co\x64\Debug>

     

    With 19.1.0.166 I get an ICE:

    1>------ Rebuild All started: Project: co, Configuration: Debug x64 ------
    1>Deleting intermediate files and output files for project 'co', configuration 'Debug|x64'.
    1>Compiling with Intel(R) Visual Fortran Compiler 19.1.0.166 [Intel(R) 64]...
    1>eg.f90
    1>04010002_1529
    1>C:\prog\test\co\eg.f90(26): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
    1>compilation aborted for C:\prog\test\co\eg.f90 (code 1)
    1>
    1>Build log written to  "file://C:\prog\test\co\x64\Debug\BuildLog.htm"
    1>co - 1 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

     

    0 Kudos
    FortranFan
    Honored Contributor III
    871 Views

    Well, that's a shame on the compiler.  Component-by-component assignments work:  Intel Fortran compiler implementation appears to have issues with intrinsic assignment of derived types with ALLOCATABLE components in a coarray context and your support request here will hopefully get the Intel Fortran team to improve this aspect of their implementation.

       type :: t
          real(8)              :: x1, x2, x3
          real(8), allocatable :: xn(:)
          integer              :: i1, i2, i3
          integer, allocatable :: in(:)
       end type
       character(len=*), parameter :: fmtg = "(g0,t15,g0,t35,*(g0,1x))"
    
       type(t), save :: foo
  • integer :: i if ( this_image() == 1 ) then foo%x1 = 20. foo%x2 = 30. foo%x3 = 40. foo%xn = [41., 42., 43., 44.] foo%i1 = 11 foo%i2 = 21 foo%i3 = 31 foo%in = [51, 52, 53, 54] end if sync all if ( this_image() /= 1 ) then foo%x1 = foo[1]%x1 foo%x2 = foo[1]%x2 foo%x3 = foo[1]%x3 foo%xn = foo[1]%xn foo%i1 = foo[1]%i1 foo%i2 = foo[1]%i2 foo%i3 = foo[1]%i3 foo%in = foo[1]%in end if sync all if ( this_image() == 1 ) then print fmtg, "Image #", "foo%x1", "foo%in" do i = 1, num_images() print fmtg, i, foo%x1, foo%in end do end if end
  • C:\Temp>ifort /standard-semantics /warn:all /stand:f18 /Qcoarray:shared /Qcoarray-num-images=8 p.f90
    Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
    Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.
    
    Microsoft (R) Incremental Linker Version 14.24.28316.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    -out:p.exe
    -subsystem:console
    p.obj
    
    C:\Temp>p.exe
    Image #       foo%x1              foo%in
    1             20.00000000000000   51 52 53 54
    2             20.00000000000000   51 52 53 54
    3             20.00000000000000   51 52 53 54
    4             20.00000000000000   51 52 53 54
    5             20.00000000000000   51 52 53 54
    6             20.00000000000000   51 52 53 54
    7             20.00000000000000   51 52 53 54
    8             20.00000000000000   51 52 53 54
    
    C:\Temp>

    But now, an ICE is always a compiler bug so Intel Fortran team should immediately accept that as a legitimate issue to work on.

     

    FortranFan
    Honored Contributor III
    871 Views

    Hopefully the couple of examples shown below can be reviewed by Intel Fortran team for consideration of cases toward their library of quality assurance (QA) and acceptance and validation checks of modern Fortran feature implementations such as coarrays and later toward their test suite for regression testing.  That is, assuming such test libraries/suites are even present, at times one really has to wonder considering the defects that show up as to whether the vendor even bothers to do basic checks of their own with the implemented functionality or relies entirely on the users to discover the problems.

    Example 1: defined assignment works with a simple derived type:

    module m
    
       type :: t
          integer :: n = 0
       contains
          procedure, pass(lhs) :: assign_t
          generic :: assignment(=) => assign_t
       end type
    
    contains
    
       elemental subroutine assign_t( lhs, rhs )
          class(t), intent(inout) :: lhs
          type(t), intent(in)     :: rhs
          lhs%n = rhs%n
       end subroutine
    
    end module
     
       use m, only : t 
       character(len=*), parameter :: fmtg = "(g0,t15,g0)"
    
       type(t), save :: foo
  • integer :: i if ( this_image() == 1 ) then foo%n = 42 end if sync all if ( this_image() /= 1 ) then foo = foo[1] end if sync all if ( this_image() == 1 ) then print fmtg, "Image #", "foo%n" do i = 1, num_images() print fmtg, i, foo%n end do end if end
  • Example 2: change the component in example 1 above to have an ALLOCATABLE attribute and the program does not work.

    module m
    
       type :: t
          integer, allocatable :: n
       contains
          procedure, pass(lhs) :: assign_t
          generic :: assignment(=) => assign_t
       end type
    
    contains
    
       elemental subroutine assign_t( lhs, rhs )
          class(t), intent(inout) :: lhs
          type(t), intent(in)     :: rhs
          lhs%n = rhs%n
       end subroutine
    
    end module
     
       use m, only : t 
       character(len=*), parameter :: fmtg = "(g0,t15,g0)"
    
       type(t), save :: foo
  • integer :: i if ( this_image() == 1 ) then foo%n = 42 end if sync all if ( this_image() /= 1 ) then foo = foo[1] end if sync all if ( this_image() == 1 ) then print fmtg, "Image #", "foo%n" do i = 1, num_images() print fmtg, i, foo%n end do end if end
  • C:\Temp>ifort /standard-semantics /warn:all /stand:f18 /Qcoarray:shared /Qcoarray-num-images=8 p.f90
    Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
    Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.
    
    Microsoft (R) Incremental Linker Version 14.24.28316.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    -out:p.exe
    -subsystem:console
    p.obj
    
    C:\Temp>p.exe
    forrtl: severe (157): Program Exception - access violation
    In coarray image 6
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 3
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 5
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 4
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 8
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 7
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    forrtl: severe (157): Program Exception - access violation
    In coarray image 2
    Image              PC                Routine            Line        Source
    p.exe              00007FF6BE801176  Unknown               Unknown  Unknown
    p.exe              00007FF6BE858E5E  Unknown               Unknown  Unknown
    p.exe              00007FF6BE8591E0  Unknown               Unknown  Unknown
    KERNEL32.DLL       00007FFBBB8137E4  Unknown               Unknown  Unknown
    ntdll.dll          00007FFBBBE3CB81  Unknown               Unknown  Unknown
    
    
    C:\Temp>

     

    Reply