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

Function returning a pointer inside OpenMP loop

AndresMG
Beginner
518 Views

The following code does not compile with ifx -qopenmp (2023.0.0 20221201) but it does with ifort -qopenmp (2021.8.0 20221119):

 

module main_mod

    use iso_fortran_env, only: rp => real64

    implicit none

    type statevec_t
        real(rp), allocatable :: data(:, :)
    contains
        procedure :: dof => statevec_dof
    end type statevec_t

    interface statevec_t
        module procedure statevec_initialize
    end interface statevec_t

!   ========
    contains
!   ========

    function statevec_initialize(nvars, ndofs) result(sol)
        integer, intent(in) :: nvars
        integer, intent(in) :: ndofs
        type(statevec_t)    :: sol

        allocate(sol % data(nvars, ndofs))

    end function statevec_initialize

    function statevec_dof(this, idof) result(sol)
        class(statevec_t), target, intent(in) :: this
        integer,                   intent(in) :: idof
        real(rp),          pointer            :: sol(:)

        sol => this % data(:, idof)

    end function statevec_dof

end module main_mod

!==========================================================================
!==========================================================================

program main

    use main_mod, only: rp, statevec_t

    implicit none

    integer :: nv = 4
    integer :: ndof = 6000000

    type(statevec_t) :: solution

    real(rp), pointer :: Qi(:)

!   Initialization
!   --------------
    solution = statevec_t(nv, ndof)
    call random_number(solution % data)

!   Associate
!   ---------
    do concurrent (integer :: i = 1 : ndof) shared(solution)
        associate(Qi => solution % dof(i))  !< Compiler error
            Qi = 3.0_rp * Qi
        end associate
    end do

!   Pointer
!   -------
    do concurrent (integer :: i = 1 : ndof) shared(solution) local(Qi)
        Qi => solution % dof(i)  !< Compiler error
        Qi = 3.0_rp * Qi
    end do

!   Direct assignment
!   -----------------
    do concurrent (integer :: i = 1 : ndof) shared(solution)
        solution % dof(i) = 3.0_rp * solution % dof(i)  !< Compiler error
    end do

end program main

 

Any of the three options in lines 65, 73 and 80 returns a compiler error. Note that the issue is related to the -qopenmp flag. Both compilers work fine without it.

I have read through the list in https://www.intel.com/content/www/us/en/developer/articles/technical/fortran-language-and-openmp-features-in-ifx.html and I could not find any reference to this issue (although it was implemented for sequential compilations at some point during 2022).

Labels (3)
0 Kudos
1 Solution
Barbara_P_Intel
Moderator
314 Views

This issue is fixed in oneAPI 2023.2.0 that was released this week.

Please download the new release and check it out!



View solution in original post

0 Kudos
3 Replies
Barbara_P_Intel
Moderator
447 Views

Thanks for reporting this. I filed a bug, CMPLRLLVM-44595.



0 Kudos
Barbara_P_Intel
Moderator
315 Views

This issue is fixed in oneAPI 2023.2.0 that was released this week.

Please download the new release and check it out!



0 Kudos
AndresMG
Beginner
297 Views

I confirm it is fixed, at least with my setup. It also seems that the compiler is able to inline the function call in this simple case.

Thank you for the bug report and the quick response from the developers.

0 Kudos
Reply