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

Seg fault for conjugate transpose of a 2D array


Please consider the following minimal Fortran program:

program ft
    implicit none

    integer :: i, j, n
    double complex, allocatable :: a(:, :), z(:, :), t(:, :)

    allocate(a(n, n))
    allocate(z(n, n))
    allocate(t(n, n))

    a = cmplx(1.0d0, -2.0d0)

    z = transpose(conjg(a))
    ! t = conjg(a)
    ! z = transpose(t)

end program ft

I find that this code gives a seg fault when compiled with ifort (now using 17.0.4 20170411, also tried with 15), but does not seg fault with gfortran. The seg fault is caused by the line 

z = transpose(conjg(a))

However, if you comment this line and uncomment the next two lines, which do the same thing in two separate steps, the code runs without problems. The same behaviour is observed if using dconjg instead of conjg.

Some investigation also shows that small 2D arrays do not seg fault with ifort (and the resulting conjugate transpose array z gives the correct result), but when n becomes too large the code starts seg faulting.

If anyone could help me understand this behaviour I would be very grateful.

Thank you very much.

0 Kudos
1 Reply

Intel uses stack for temporary variables - your function calls require temporary copies of very large arrays and you exceed stack.


0 Kudos