x64 LAPACK 使控制台应用程序崩溃(但不是 x86)
x64 LAPACK crashes Console Application (but not x86)
问题
我写这篇 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
更新
这 表明它可能与销毁对象并将句柄返回给 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
问题已解决mingw-w64 dlls (v6.4)重命名如下:
请注意,LAPACK 和 BLAS dll 是从 here 获得的。
问题
我写这篇 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
更新
这
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
问题已解决mingw-w64 dlls (v6.4)重命名如下:
请注意,LAPACK 和 BLAS dll 是从 here 获得的。