Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Gianluca_G_
Beginner
81 Views

MKL in C#

Hello,

I'm testing MKL in a C# application.

I have to solve a linear system of complex matrix, so first of all I want to understand how the libraries works. 

I'm not expert of c++, and Marshaling too so I have tried to define the dll as best as I could. I have used the library installed with Parallel Studio XE.

 The example that I have done, doesn't work is there any one that can help me to understand why? 

  [SuppressUnmanagedCodeSecurity]
    internal sealed class MKLWrapper
    {
        private MKLWrapper()
        {
        }

        [DllImport("mkl_rt.dll", ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int LAPACKE_zgesv(
            int matrix_layout,
            int n,
            int nrhs,
            [In, Out] Complex[,] input_matrix,
            int lda,
            [In, Out] int[] ipiv,
            [In, Out] Complex[,] b,
            int ldb
        );


        public static void Test2()
        {
            Complex[,] A = new Complex[3,3];
            Complex[,] b = new Complex[3,1];
           
            //r1
            A[0, 0] = 12;
            A[0, 1] = 1;
            A[0, 2] = 1;
            //r2
            A[1, 0] = 1;
            A[1, 1] = 12;
            A[1, 2] = 1;
            //r3
            A[2, 0] = 1;
            A[2, 1] = 1;
            A[2, 2] = 12;

            b[0, 0] = 16;
            b[1, 0] = 16;
            b[2, 0] = 16;

            int mat_layout = A.GetLength(0);

            int n = A.GetLength(0);
            int nrhs = 1;
            int lda = n;
            int ldb = n;
            int info = 1;

            int[] ipiv = new int;

            info = MKLWrapper.LAPACKE_zgesv(mat_layout, n, nrhs, A, lda, ipiv, b, ldb);
            if (info == 0)
                Console.WriteLine("Calculation completed!");
            else
                Console.WriteLine("Calculation Error!");
        }

 

Thankyou very much

Gianluca

0 Kudos
2 Replies
Gianluca_G_
Beginner
81 Views

this is the solution:

The function accept the input matrix in a vector form.
           

            int LAPACK_ROW_MAJOR = 101;
            int LAPACK_COL_MAJOR = 102;

            Complex[] A = new Complex[3*3];
            Complex[] b = new Complex[3];

            A[0] = 12; A[1] = 1; A[2] = 1; //r1
            A[3] = 1; A[4] = 12; A[5] = 1; //r2
            A[6] = 1; A[7] = 1; A[8] = 12; //r3

            b[0] = 16; b[1] = 16; b[2] = 16;

            int mat_layout = LAPACK_COL_MAJOR;

            int n = 3;
            int nrhs = 1;
            int lda = n;
            int ldb = n;
            int info = 1;

            int[] ipiv = new int;


            info = MKLWrapper.LAPACKE_zgesv(mat_layout, n, nrhs, A, lda, ipiv, b, ldb);
            if (info == 0)
            {
                Console.WriteLine("Calculation completed!");
            }
            else
                Console.WriteLine("Calculation Error!");

 

Kevin_O_Intel1
Employee
81 Views

 

Hi,

I think you are in the wrong forum. This is the Advisor XE forum.

You need the forum on MKL:

https://software.intel.com/en-us/forums/intel-math-kernel-library

Regards,

Kevin

 

 

Reply