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

Ifort 19.0.2 with -O2: Compilation hangs when allocating Array to 0-size

Diehl__Martin
Novice
572 Views

I am using the newest Ifort compiler and the compilation hangs (running forever) when I compile with -O2. I could narrow it down to a few lines of code where an array is allocated to zero size. The following example demonstrates what I am doing, but compiles without any issues. The actual code (part of a bigger project) is attached. It requires some libraries and MPI to build/

program allocate_zero                                                                               
                                                                                                    
  implicit none                                                                                     
  type :: tParameters                                                                               
    real, allocatable, dimension(:,:) :: &                                                          
      gdot0_slip, &                                                                                  !< reference shear strain rate for slip
      gdot0_twin                                                                                    
  end type                                                                                          
                                                                                                    
 type(tParameters), dimension(:), allocatable :: param                                              
 integer :: i                                                                                       
                                                                                                    
 allocate(param(3))                                                                                 
                                                                                                    
 do i = 1, 3                                                                                        
 associate(p => param(i))                                                                           
   if (i > 2) then                                                                                  
    allocate(p%gdot0_slip(0,0))                                                                     
   endif                                                                                            
 end associate                                                                                      
 enddo                                                                                              
                                                                                                    
end program 

 

0 Kudos
3 Replies
Williams__Ben
Beginner
572 Views
I only have access to 19.0.0.117 at the moment so can't test your example code properly in 19.0.2- for clarity though, does the example hang? All you say above is it compiles correctly. If the example does hang then there's a few things you could try: 1) remove the associate block and explicitly state param(i) in the allocation 2) remove the do loop and explicitly state param(3) in the allocate. 3) allocate to size 1,1 - assuming you haven't done this already. If that works it would indicate the presence of a bug for zero-sized arrays. 4) check stat on the allocate (doubt it'll ever leave if it's hanging though) 5) check it works with -O0 or -O1. I doubt any of these suggestions will change the hang but if they do then it might indicate where the problem is more specifically.
0 Kudos
Juergen_R_R
Valued Contributor I
572 Views

I don't see any hanging of the program that you posted, neither with -O2 nor without. You mentioned MPI, maybe that is related to MPI? Or is the problem only in the longer example that you attached.

0 Kudos
Diehl__Martin
Novice
572 Views

Thanks for the help.

To make sure, I cannot reproduce the behavior with a minimal working example.

I have investigated the behavior in more detail and figured out that is is related to the use of the following function which is called after the code I erroneously identified as the culprit in the original post:

!--------------------------------------------------------------------------------------------------
!> @brief vector expansion
!> @details takes a set of numbers (a,b,c,...) and corresponding multiples (x,y,z,...)
!> to return a vector of x times a, y times b, z times c, ... 
!--------------------------------------------------------------------------------------------------
pure function math_expand(what,how)

 implicit none
 real(pReal),   dimension(:), intent(in) :: what
 integer, dimension(:), intent(in) :: how
 real(pReal), dimension(sum(how)) ::  math_expand
 integer :: i

 if (sum(how) == 0) &
   return

 do i = 1, size(how)
   math_expand(sum(how(1:i-1))+1:sum(how(1:i))) = what(mod(i-1,size(what))+1)
 enddo

end function math_expand

I use this function in 6 files and I causes problems only in 2 of them. As soon as I comment it out, it compiles.

It is always used like

prm%burgers_twin = math_expand(prm%burgers_twin,prm%Ntwin)

i.e. the left side gets reallocated according to the return value of the expansion function.

0 Kudos
Reply