Skip to content

SIGILL on Apple silicon #5818

@Chengcheng-Xiao

Description

@Chengcheng-Xiao

Has been reproduced on

OS/CPU: macOS Tahoe 26.5, M4 and M2 CPU
Compiler: GCC (gfortran) 15.2.0
OpenBLAS 0.3.32 (installed via macports, build formula)

and
OS/CPU: - / M2 CPU
Compiler: GCC (gfortran) 15.2.0
OpenBLAS 0.3.33 (installed via homebrew, build formula)

Minimum test code:

program test_zgetrf
    implicit none

    integer, parameter :: n = 4
    ! integer, parameter :: n = 3
    integer :: i, j, info
    integer :: ipiv(n)
    complex(kind=kind(1.0d0)) :: A(n,n), L(n,n), U(n,n), row(n)

    do j=1,n
       do i=1,n
          ! this should trigger a divide by zero
          ! A(i,j) = i+j
          ! this should be fine
          A(i,j) = mod(i+j, n)
       end do
    end do

    ! print *, "Original matrix A:"
    ! do i = 1, n
    !     print *, A(i,:)
    ! end do

    ! LU factorization
    call zgetrf(n, n, A, n, ipiv, info)

    if (info /= 0) then
        print *, "zgetrf failed with info =", info
        stop
    end if

    print *, "LU-factorized matrix A:"
    do i = 1, n
        print *, A(i,:)
    end do

    print *, "Pivot indices:"
    print *, ipiv

    L(:,:) = 0.d0; U(:,:) = 0.d0
    do j=1,n
       L(j,j) = 1.d0
       do i=1,j
          U(i,j) = A(i,j)
       end do
       do i=j+1,n
          L(i,j) = A(i,j)
       end do
    end do
    call zgemm('N', 'N', n, n, n, (1.d0, 0.d0), L, n, U, n, (0.d0, 0.d0), A, n)
    do i=n,1,-1
       row(:) = A(i,:)
       A(i,:) = A(ipiv(i),:)
       A(ipiv(i),:) = row(:)
    end do

    print *, "P.L.U="
    do i = 1, n
        print *, A(i,:)
    end do

end program test_zgetrf

When compiled with gfortran (15.2.0)

gfortran -ffpe-trap=zero -L/opt/local/lib -lopenblas test_zgetrf.F90

produces

Program received signal SIGILL: Illegal instruction.

Note that this only happens with -ffpe-trap=zero. Without it, everything works fine.

Switching to apple's accelerate framework then it works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug in other softwareCompiler, Virtual Machine, etc. bug affecting OpenBLAS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions