Issue
I have written this console app to compare the performance of ARPACK and LAPACK for a matrix of interest. After completing the calculations, the x64 application exits suddenly with the following error:
`The program '[8224] x64Project.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'
Question
In the tests that i have done, the x86 project does not. Any ideas as to what the cause of this might be?
I suspect the error may be the incorrect use of DLLImport (although the answers are correct) or the LAPACK library or one of its dependencies:
Update
This post indicates that it could be something to do with destructing the objects and returning the handles to Windows. But i don't know how this is applicable to my situation.
Example use of 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
The problem is solved by using the following mingw-w64 dlls (v6.4) renamed as follows:
Note the LAPACK and BLAS dlls were obtained from here.