Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26734 Discussions

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


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
  end type                                                                                          
 type(tParameters), dimension(:), allocatable :: param                                              
 integer :: i                                                                                       
 do i = 1, 3                                                                                        
 associate(p => param(i))                                                                           
   if (i > 2) then                                                                                  
 end associate                                                                                      
end program 


0 Kudos
3 Replies
I only have access to 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.
Valued Contributor I

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.


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

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

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.