x64 LAPACK使控制台应用程序崩溃(但没有使x86崩溃)

时间:2018-10-19 05:54:32

标签: visual-studio linear-algebra lapack

问题

我已经写了这个console app来比较ARPACK和LAPACK在感兴趣的矩阵上的性能。完成计算后,x64应用程序突然退出,并出现以下错误:

`The program '[8224] x64Project.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'

问题

在我完成的测试中,x86项目没有。关于这可能是什么原因的任何想法?

我怀疑错误可能是不正确使用DLLImport(尽管答案正确)或LAPACK库或其依赖项之一:

  • liblapack.dll
  • libblas.dll
  • libquadmath_64-0.dll
  • libgcc_s_seh_64-1.dll
  • libgfortran_64-3.dll

更新

post表示可能与销毁对象并将句柄返回Windows有关。但是我不知道这如何适用于我的情况。

使用DLLImport的示例

<Runtime.InteropServices.DllImport("liblapack", EntryPoint:="dsygv_", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl), Security.SuppressUnmanagedCodeSecurity>
Private Sub Lapack_dsygv(ByRef itype As Integer, ByRef jobz As Char, ByRef uplo As Char, ByRef n As Integer, ByVal A As Double(), ByRef lda As Integer,
                         ByVal B As Double(), ByRef ldb As Integer, ByVal w As Double(), ByVal work As Double(), ByRef lwork As Integer, ByRef info As Integer)
End Sub
Public Sub Dsygv(itype As Integer, jobz As Char, uplo As Char, n As Integer, A As Double(), lda As Integer, B As Double(), ldb As Integer, w As Double(), ByRef info As Integer)
    Dim lwork As Integer = -1
    Dim work As Double() = New Double(0) {0.0}
    Lapack_dsygv(itype, jobz, uplo, n, A, lda, B, ldb, w, work, lwork, info)
    If info <> 0 OrElse work(0) <= 0.0 Then Return
    lwork = CInt(work(0))
    work = New Double(lwork - 1) {}
    Lapack_dsygv(itype, jobz, uplo, n, A, lda, B, ldb, w, work, lwork, info)
End Sub
Public Function EigSymmetric1(A_UpperTriangle_EigenVectors As Double(), B_UpperTriangle As Double()) As Double()
    Dim n As Integer = CInt(Math.Sqrt(A_UpperTriangle_EigenVectors.GetLength(0)))
    Dim info As Integer = -1
    Dim w As Double() = New Double(n - 1) {}
    Dsygv(1, "N"c, "U"c, n, A_UpperTriangle_EigenVectors, n, B_UpperTriangle, n, w, info)
    If info = 0 Then
        Return w
    ElseIf info < 0 Then
        Throw New Exception("eigSymm: invalid parameter #" & (-info))
    Else
        If info <= n Then
            Throw New Exception(String.Format("eigSymm: did not converge! {0} off-diagonal elements unequal 0", info))
        ElseIf info < 2 * n Then
            Throw New Exception("eigSymm: B must be positive definite!")
        Else
            Throw New Exception("eigSymm: unknown error")
        End If
    End If
End Function

1 个答案:

答案 0 :(得分:0)

使用以下重命名为以下名称的mingw-w64 dlls (v6.4)解决了该问题:

dll names

请注意,LAPACK和BLAS dll是从here获得的。