Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

C# Nonlinear Optimization Problem Solvers

Michael_W_1
Beginner
364 Views

Hi,

I'm using Intel MKL from C#. In General it works. I want to use the Nonlinear Optimization Problem Solvers and I've translated the example, see http://software.intel.com/en-us/node/471540. But the dtrnlsp_solve gives me sometimes a memory exception (attempt to read write protected memory).  I've attached all the dllimports, see below.

[DllImport("mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]

internal static extern int dtrnlsp_init(

ref IntPtr handle, ref int n, ref int m, IntPtr x, [In] double[] eps, ref int iter1, ref int iter2, ref double rs);

[DllImport("mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]

internal static extern int dtrnlsp_check(

ref IntPtr handle, ref int n, ref int m, IntPtr fjac, IntPtr fvec, [In] double[] eps, [In, Out] int[] info);

[DllImport("mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]

internal static extern int dtrnlsp_solve(

ref IntPtr handle, [In, Out] IntPtr fvec, [In] IntPtr fjac, ref int RCI_Request);

[DllImport("mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]

internal static extern int dtrnlsp_get(

ref IntPtr handle, ref int iter, ref int st_cr, ref double r1, ref double r2);

[DllImport("mkl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]

internal static extern int dtrnlsp_delete(

ref IntPtr handle);

Regards Michael

 

0 Kudos
2 Replies
Ying_H_Intel
Employee
364 Views

Hi Michael W,

The import code looks no problem. What of MKL version are you using? Could you please attach the whole cs file, so we can test?

Here are some C# example we had  , http://software.intel.com/en-us/articles/using-intel-mkl-in-your-c-program/

Best Regards,

Ying

0 Kudos
Michael_W_1
Beginner
364 Views

Hi Ying,

thank you for your answer.

MKL Version 11.1 Update 2. An example script which crashes reproducible I cannot provide at the moment. Once I have one I will provide it.

An other idea: Is it possible to redefine MKL memory function from C#. So that i_malloc is Marshal.AllocHGlobal Method? I think that dtrnlsp_solve (that one which crashes) allocates memory internally to compute the updated values of x.

Regards

Michael

0 Kudos
Reply