OpenMP segfaults with allocatable array of derived type

Hello, unfortunately I am having a segfault issue with the nvfortran compiler. When using OpenMP to parallelize a loop with an allocatable array of derived types the compiler is generating code that results in a segfault. Bellow is a simplified version of my code that reproduces the error on nvfortran but works fine with gfortran.

module myTypeMod
    integer, parameter :: realType = kind(0.0d0)
                      
    type myType
    contains
        procedure :: create=>create_type
    end type myType

contains

    subroutine create_type(d)
        class(myType) :: d
        write(*,*) 'hi from create'
    end subroutine create_type

end module myTypeMod
  
  
  program main
    use myTypeMod,      only : myType
    implicit none
    type(myType), dimension(:), allocatable :: myTypeArr1
  
    call testOMP(myTypeArr1)

contains
    subroutine testOMP(myTypeArr)
        use myTypeMod,      only : myType
        type(myType), dimension(:), allocatable :: myTypeArr

        integer :: idx, n
        n = 3

        allocate(myTypeArr(n))
        
        !$omp parallel default(none) &
        !$omp shared(myTypeArr,n) &
        !$omp private(idx)
        !$omp do schedule(dynamic)
        clusterLoop: do idx=1, n
            call myTypeArr(idx)%create()
         
        end do clusterLoop
        !$omp end do
        !$omp end parallel
        
    end subroutine testOMP
    

    
  end program main 

I am compiling and running the program with

> nvfortran  -O0 -mp  -o reproducer_omp reproducer_omp.f90  && ./reproducer_omp
zsh: segmentation fault (core dumped)  ./reproducer_omp

Using the latest version of nvfortran

> nvfortran --version

  nvfortran 25.1-0 64-bit target on x86-64 Linux -tp skylake-avx512 
  NVIDIA Compilers and Tools
  Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.

What I have tried

What has no effect

  • using static omp scheduling
  • setting the scirpt to use one thread with export OMP_NUM_THREADS=1
  • different optimization levels
  • using the older 24.7 compiler

what prevents the issue

  • removing the OMP derictives or compiling without -mp
  • making myTypeArr statically allocated

Hi joanib14,

Thanks for the report and the great reproducing example!

Indeed, it looks to be a compiler issue with the polymorphic type in the OpenMP region. I’ve added a problem report, TPR #37065, and sent it to engineering.

I did test your code with the LLVM based Fortran compiler we’re developing, and it worked there. So to set your expectations, there’s a good chance that engineering wont fix this in the current nvfortran and we may need to wait for the new compiler to be released. I don’t have an ETA on when that will be.

-Mat

1 Like