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

Calling MKL Library from C# - Intel broken links

JohnNichols
Valued Contributor III
602 Views

Dear Intel:

All of the links on the Intel site that provide sample of how to call MKL from C# are broken - I cannot download the files.  Yes I have tried all of them.

I am trying to call the PARDISO routine I have tried this code - I used the dll from the pardiso site - just to see if I could get anything working.

Your help appreciated -

JMN

using System.IO;
using System;
using System.Runtime.InteropServices;

class Program
{
    
    [DllImport("C:\\Users\\John\\Documents\\Visual Studio 2013\\Projects\\Program056 - WSA\\WSC\\Solver\\Solver\\Solver\\Debug\\Solver.dll")]
    
    public static extern void Solver();

    [DllImport("C:\\Users\\John\\Documents\\Visual Studio 2013\\Projects\\Program056 - WSA\\WSC\\Solver\\Solver\\Solver\\Debug\\libpardiso500-WIN-X86-64.dll")]

    public static extern void pardinit(int[] pt, int maxfct, int[] iparm );
    static void Main(string[] args)
    {
        int[] pt = new int[64];
        int maxfct;
        int[] iparm = new int[64];
        double[] p2 = new double[] { 0.5, 1.5, 3.5 };
        Solver();
        maxfct = 11; 
        pardinit(pt, maxfct, iparm);
        //Console.WriteLine(t2.ToString());
        //returns 3.84057283
    } 
}

Capture.PNG

0 Kudos
9 Replies
JohnNichols
Valued Contributor III
602 Views

Dear Fellow Programmers:

I spent the best part of a day looking for the method for calling PARDISO from C#, the INTEL links pointing to the MKL examples for C#. The links are broken and the extensive notes are not quite enough to sort out the problem, close but not quite.

I finally found a copy of the PARDISO.cs program on the forum.  Here is a copy of the program - I did not write it - it appears to work nicely.

You need to set the build - unsafe setting on the properties page, and put the PARDISO DLL in the debug directory or where you have the exe file. (I used an academic copy of the PARDISO DLL - I was sick of trying to determine which DLL I really needed from MKL. Perhaps someone could tell me.)

JMN

 

using System;
using System.Security;
using System.Runtime.InteropServices;
using mkl;

public unsafe class test_pardiso
{
    private test_pardiso() { }
    public static int Main(string[] args)
    {
        /* Matrix data. */
        int n = 108;
        int[] ia/*[9]*/ = new int[] { 1, 8, 15, 19, 26, 33, 37, 47, 59, 71, 76, 81, 90, 96, 102, 108, 112, 114, 120, 127, 136, 142, 149, 158, 164, 168, 172, 174, 178, 182, 184, 191, 198, 202, 209, 216, 220, 232, 244, 258, 267, 274, 285, 291, 297, 303, 307, 309, 315, 324, 333, 341, 352, 363, 371, 375, 379, 381, 385, 389, 391, 396, 401, 404, 409, 414, 416, 422, 428, 431, 437, 443, 446, 448, 450, 452, 454, 456, 457, 462, 467, 470, 475, 480, 482, 488, 494, 497, 503, 509, 512, 514, 516, 518, 520, 522, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, 543, 545, 547 };
        int[] ja/*[18]*/ = new int[] { 1, 5, 19, 23, 67, 71, 97, 2, 4, 20, 22, 68, 70, 98, 3, 21, 69, 99, 2, 4, 20, 22, 68, 70, 100, 1, 5, 19, 23, 67, 71, 101, 6, 24, 72, 102, 7, 8, 9, 13, 14, 15, 19, 37, 38, 39, 7, 8, 9, 12, 13, 14, 15, 20, 24, 37, 38, 39, 7, 8, 9, 11, 13, 14, 15, 21, 23, 37, 38, 39, 10, 12, 16, 18, 22, 9, 11, 17, 21, 23, 8, 10, 11, 12, 16, 17, 18, 20, 24, 7, 8, 9, 13, 14, 15, 7, 8, 9, 13, 14, 15, 7, 8, 9, 13, 14, 15, 10, 12, 16, 18, 11, 17, 10, 11, 12, 16, 17, 18, 1, 5, 7, 19, 23, 25, 29, 2, 4, 8, 12, 20, 22, 24, 26, 28, 3, 9, 11, 21, 23, 27, 2, 4, 10, 20, 22, 26, 28, 1, 5, 9, 11, 19, 21, 23, 25, 29, 6, 8, 12, 20, 24, 30, 19, 23, 25, 29, 20, 22, 26, 28, 21, 27, 20, 22, 26, 28, 19, 23, 25, 29, 24, 30, 31, 35, 49, 53, 85, 89, 103, 32, 34, 50, 52, 86, 88, 104, 33, 51, 87, 105, 32, 34, 50, 52, 86, 88, 106, 31, 35, 49, 53, 85, 89, 107, 36, 54, 90, 108, 7, 8, 9, 37, 38, 39, 42, 43, 44, 45, 49, 54, 7, 8, 9, 37, 38, 39, 42, 43, 44, 45, 50, 54, 7, 8, 9, 37, 38, 39, 40, 41, 43, 44, 45, 51, 52, 53, 39, 40, 41, 42, 46, 48, 51, 52, 53, 39, 40, 41, 47, 51, 52, 53, 37, 38, 40, 41, 42, 46, 47, 48, 49, 50, 54, 37, 38, 39, 43, 44, 45, 37, 38, 39, 43, 44, 45, 37, 38, 39, 43, 44, 45, 40, 42, 46, 48, 41, 47, 40, 41, 42, 46, 47, 48, 31, 35, 37, 42, 49, 53, 54, 55, 59, 32, 34, 38, 42, 50, 52, 54, 56, 58, 33, 39, 40, 41, 51, 52, 53, 57, 32, 34, 39, 40, 41, 50, 51, 52, 53, 56, 58, 31, 35, 39, 40, 41, 49, 51, 52, 53, 55, 59, 36, 37, 38, 42, 49, 50, 54, 60, 49, 53, 55, 59, 50, 52, 56, 58, 51, 57, 50, 52, 56, 58, 49, 53, 55, 59, 54, 60, 61, 65, 67, 71, 73, 62, 64, 68, 70, 74, 63, 69, 75, 62, 64, 68, 70, 76, 61, 65, 67, 71, 77, 66, 72, 1, 5, 61, 65, 67, 71, 2, 4, 62, 64, 68, 70, 3, 63, 69, 2, 4, 62, 64, 68, 70, 1, 5, 61, 65, 67, 71, 6, 66, 72, 61, 73, 62, 74, 63, 75, 64, 76, 65, 77, 78, 79, 83, 85, 89, 91, 80, 82, 86, 88, 92, 81, 87, 93, 80, 82, 86, 88, 94, 79, 83, 85, 89, 95, 84, 90, 31, 35, 79, 83, 85, 89, 32, 34, 80, 82, 86, 88, 33, 81, 87, 32, 34, 80, 82, 86, 88, 31, 35, 79, 83, 85, 89, 36, 84, 90, 79, 91, 80, 92, 81, 93, 82, 94, 83, 95, 96, 1, 97, 2, 98, 3, 99, 4, 100, 5, 101, 6, 102, 31, 103, 32, 104, 33, 105, 34, 106, 35, 107, 36, 108 };
        double[] aData/*[18]*/ = new double[] { 1004863793451.0912, 29747807.699465655, -4854325794.24985, 30339536.252052631, -9467656.8413916249, -591728.55258697656, -1000000000000, 1004863793451.0912, -29747807.699465655, -4854325794.24985, -30339536.252052631, -9467656.8413916249, 591728.55258697656, -1000000000000, 1015070926799.397, -14550679055.962502, -520247743.43446976, -1000000000000, -29747807.699465655, 1001984556.0448495, 30339536.252052631, -1555322.6131014798, -591728.55258697656, 23976.840950824288, -1000000000, 29747807.699465655, 1001984556.0448495, -30339536.252052631, -1555322.6131014798, 591728.55258697656, 23976.840950824288, -1000000000, 1001352347.4859278, -1342265.165318656, -10082.320609195149, -1000000000, 100879182042193.52, -280441127938.47241, -165661425786.43942, -879138647269.59583, 280541855691.4549, 165720927412.6738, -100000000000000, -43394923.915910393, -100727752.98250037, -59501626.234388426, -280441127938.47241, 100349043572104, -384531223229.71167, -996835443037.97449, 280541855691.4549, -348809764107.44543, 384669337658.04913, -100000000000000, -996835443037.97449, -100727752.98250039, -233807996.54273936, -138114428.3374832, -165661425786.43942, -384531223229.71167, 100772850754210.3, 996835443037.97449, 165720927412.6738, 384669337658.04913, -772769167628.15649, -100000000000000, 996835443037.97449, -59501626.234388426, -138114428.3374832, -81586582.140285462, 1100000000000, 3.0517578125E-05, -1000000000000, -3.0517578125E-05, -100000000000, 996835443037.97449, 1109936809004.967, -999999999999.99988, -996835443037.97449, -90063190995.032852, -996835443037.97449, 3.0517578125E-05, -6.103515625E-05, 1109936809004.967, -3.0517578125E-05, 6.103515625E-05, -1000000000000, 996835443037.97449, -90063190995.032852, -879138647269.59583, 280541855691.4549, 165720927412.6738, 879138647269.59583, -280541855691.4549, -165720927412.6738, 280541855691.4549, -348809764107.44543, 384669337658.04913, -280541855691.4549, 348809764107.44543, -384669337658.04913, 165720927412.6738, 384669337658.04913, -772769167628.15649, -165720927412.6738, -384669337658.04913, 772769167628.15649, -1000000000000, -3.0517578125E-05, 1000000000000, 3.0517578125E-05, -999999999999.99988, 999999999999.99988, -3.0517578125E-05, 6.103515625E-05, -1000000000000, 3.0517578125E-05, -6.103515625E-05, 1000000000000, -4854325794.24985, -30339536.252052631, -100000000000000, 100009708651595.02, 0.0027523115277290344, -4854325800.7687864, 30339536.254804943, -4854325794.24985, 30339536.252052631, -100000000000000, 996835443037.97449, 100009708651595.02, -0.0027523115277290344, 996835443037.97449, -4854325800.7687864, -30339536.254804943, -14550679055.962502, -100000000000000, -996835443037.97449, 100029101358130.14, -996835443037.97449, -14550679074.182804, -30339536.252052631, -1555322.6131014798, -100000000000, -0.0027523115277290344, 100003869133.63542, 30339536.254804943, -1555322.6155067345, 30339536.252052631, -1555322.6131014798, 996835443037.97449, -90063190995.032852, 0.0027523115277290344, -996835443037.97449, 109940678138.60257, -30339536.254804943, -1555322.6155067345, -1342265.165318656, -996835443037.97449, -90063190995.032852, 996835443037.97449, 109939493535.29947, -1342265.1669994351, -4854325800.7687864, -30339536.254804943, 4854325800.7687864, -30339536.254804943, -4854325800.7687864, 30339536.254804943, 4854325800.7687864, 30339536.254804943, -14550679074.182804, 14550679074.182804, -30339536.254804943, -1555322.6155067345, 30339536.254804943, 1934566.8186917969, 30339536.254804943, -1555322.6155067345, -30339536.254804943, 1934566.8186917969, -1342265.1669994351, 1342265.1669994351, 1122369280976.2017, 764157105.65103018, -122359813319.3602, 764748834.20361722, -9467656.8413916249, -591728.55258697656, -1000000000000, 1122369280976.2017, -764157105.65103018, -122359813319.3602, -764748834.20361722, -9467656.8413916249, 591728.55258697656, -1000000000000, 1354913010127.2256, -354392762383.79108, -520247743.43446976, -1000000000000, -764157105.65103018, 1626080181.9066658, 764748834.20361722, -616470832.239028, -591728.55258697656, 23976.840950824288, -1000000000, 764157105.65103018, 1626080181.9066658, -764748834.20361722, -616470832.239028, 591728.55258697656, 23976.840950824288, -1000000000, 1477895091.9042904, -477885009.58368117, -10082.320609195149, -1000000000, -43394923.915910393, -100727752.98250037, -59501626.234388426, 100879182042193.52, -280441127938.47241, -165661425786.43942, -0.00064291833575674806, -879138647269.59583, 280541855691.4549, 165720927412.6738, -100000000000000, -0.00064291833575674806, -100727752.98250039, -233807996.54273936, -138114428.3374832, -280441127938.47241, 100349043572104, -384531223229.71167, 4253164556962.0254, 280541855691.4549, -348809764107.44543, 384669337658.04913, -100000000000000, 4253164556962.0254, -59501626.234388426, -138114428.3374832, -81586582.140285462, -165661425786.43942, -384531223229.71167, 100772850754210.3, 0.00064291833575674806, -4253164556962.0254, 165720927412.6738, 384669337658.04913, -772769167628.15649, -100000000000000, 0.00064291833575674806, -4253164556962.0254, 0.00064291833575674806, 1100000000000, -2.7344374786616117E-05, 3.0517578125E-05, -1000000000000, -3.0517578125E-05, -0.00064291833575674806, -100000000000, -2.7344374786616117E-05, -4253164556962.0254, -2.7344374786616117E-05, 1280894087485.9797, -999999999999.99988, 4253164556962.0254, -2.7344374786616117E-05, 80894087485.9798, -0.00064291833575674806, 4253164556962.0254, 3.0517578125E-05, -6.103515625E-05, 1280894087485.9797, -3.0517578125E-05, 6.103515625E-05, -1000000000000, 0.00064291833575674806, -4253164556962.0254, 80894087485.9798, -879138647269.59583, 280541855691.4549, 165720927412.6738, 879138647269.59583, -280541855691.4549, -165720927412.6738, 280541855691.4549, -348809764107.44543, 384669337658.04913, -280541855691.4549, 348809764107.44543, -384669337658.04913, 165720927412.6738, 384669337658.04913, -772769167628.15649, -165720927412.6738, -384669337658.04913, 772769167628.15649, -1000000000000, -3.0517578125E-05, 1000000000000, 3.0517578125E-05, -999999999999.99988, 999999999999.99988, -3.0517578125E-05, 6.103515625E-05, -1000000000000, 3.0517578125E-05, -6.103515625E-05, 1000000000000, -122359813319.3602, -764748834.20361722, -100000000000000, 0.00064291833575674806, 100244719626792.72, 0.0049118995666503906, 0.00064291833575674806, -122359813473.36453, 764748834.20852911, -122359813319.3602, 764748834.20361722, -100000000000000, -4253164556962.0254, 100244719626792.72, -0.0049118995666503906, -4253164556962.0254, -122359813473.36453, -764748834.20852911, -354392762383.79108, -100000000000000, -0.00064291833575674806, 4253164556962.0254, 100708785525211.34, -0.00064291833575674806, 4253164556962.0254, -354392762827.56036, -764748834.20361722, -616470832.239028, 0.00064291833575674806, -100000000000, -2.7344374786616117E-05, -0.0049118995666503906, -0.00064291833575674806, 101252060386.12906, -2.7344374786616117E-05, 764748834.20852911, -616470833.02290988, 764748834.20361722, -616470832.239028, -4253164556962.0254, -2.7344374786616117E-05, 80894087485.9798, 0.0049118995666503906, 4253164556962.0254, -2.7344374786616117E-05, 282146147872.10889, -764748834.20852911, -616470833.02290988, -477885009.58368117, -0.00064291833575674806, 4253164556962.0254, 80894087485.9798, 0.00064291833575674806, -4253164556962.0254, 281849857505.74554, -477885010.18208694, -122359813473.36453, -764748834.20852911, 122359813473.36453, -764748834.20852911, -122359813473.36453, 764748834.20852911, 122359813473.36453, 764748834.20852911, -354392762827.56036, 354392762827.56036, -764748834.20852911, -616470833.02290988, 764748834.20852911, 626030193.45051646, 764748834.20852911, -616470833.02290988, -764748834.20852911, 626030193.45051646, -477885010.18208694, 477885010.18208694, 5408879181.6480465, 11022197.95412012, -4408879181.6480465, 11022197.95412012, -1000000000, 5408879181.6480465, -11022197.95412012, -4408879181.6480465, -11022197.95412012, -1000000000, 14006193585.861744, -13006193585.861744, -1000000000, -11022197.95412012, 1352710.3345318439, 11022197.95412012, -297599.34476124332, -1000000, 11022197.95412012, 1352710.3345318439, -11022197.95412012, -297599.34476124332, -1000000, 252058.01522987871, -252058.01522987871, -9467656.8413916249, 591728.55258697656, -4408879181.6480465, -11022197.95412012, 4418346838.4894381, -10430469.401533144, -9467656.8413916249, -591728.55258697656, -4408879181.6480465, 11022197.95412012, 4418346838.4894381, 10430469.401533144, -520247743.43446976, -13006193585.861744, 13526441329.296213, 591728.55258697656, 23976.840950824288, -11022197.95412012, -297599.34476124332, 10430469.401533144, 402699.56265439169, -591728.55258697656, 23976.840950824288, 11022197.95412012, -297599.34476124332, -10430469.401533144, 402699.56265439169, -10082.320609195149, -252058.01522987871, 262140.33583907387, -1000000000, 1.0000001E+16, -1000000000, 1.0000001E+16, -1000000000, 1.0000001E+16, -1000000, 1.0000000001E+16, -1000000, 1.0000000001E+16, 1E+16, 5408879181.6480465, 11022197.95412012, -4408879181.6480465, 11022197.95412012, -1000000000, 5408879181.6480465, -11022197.95412012, -4408879181.6480465, -11022197.95412012, -1000000000, 14006193585.861744, -13006193585.861744, -1000000000, -11022197.95412012, 1352710.3345318439, 11022197.95412012, -297599.34476124332, -1000000, 11022197.95412012, 1352710.3345318439, -11022197.95412012, -297599.34476124332, -1000000, 252058.01522987871, -252058.01522987871, -9467656.8413916249, 591728.55258697656, -4408879181.6480465, -11022197.95412012, 4418346838.4894381, -10430469.401533144, -9467656.8413916249, -591728.55258697656, -4408879181.6480465, 11022197.95412012, 4418346838.4894381, 10430469.401533144, -520247743.43446976, -13006193585.861744, 13526441329.296213, 591728.55258697656, 23976.840950824288, -11022197.95412012, -297599.34476124332, 10430469.401533144, 402699.56265439169, -591728.55258697656, 23976.840950824288, 11022197.95412012, -297599.34476124332, -10430469.401533144, 402699.56265439169, -10082.320609195149, -252058.01522987871, 262140.33583907387, -1000000000, 1.0000001E+16, -1000000000, 1.0000001E+16, -1000000000, 1.0000001E+16, -1000000, 1.0000000001E+16, -1000000, 1.0000000001E+16, 1E+16, -1000000000000, 1000000000000, -1000000000000, 1000000000000, -1000000000000, 1000000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000000, 1000000000000, -1000000000000, 1000000000000, -1000000000000, 1000000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1.0000001E+16 };
        AlignedDoubleArrayPointer a = new AlignedDoubleArrayPointer(aData);

        int mtype = 11; /* Real unsymmetric matrix */
        /* RHS and solution vectors. */
        double[] bData = new double;
        bData[101] = 450;
        AlignedDoubleArrayPointer b = new AlignedDoubleArrayPointer(bData);

        double[] x = new double;
        int nrhs = 1; /* Number of right hand sides. */

        IntPtr[] pt = new IntPtr[64];
        /* Pardiso control parameters. */
        int[] iparm = new int[64];
        int maxfct, mnum, phase, error, msglvl;
        /* Auxiliary variables. */
        int i;
        //double[] ddum = new double[1]; /* Double dummy */
        //int[] idum = new int[1]; /* Integer dummy. */
        int[] perm = new int;

        /* ----------------------------------------------------------------- */
        /* .. Setup Pardiso control parameters. */
        /* ----------------------------------------------------------------- */
        for (i = 0; i < 64; i++)
        {
            iparm = 0;
        }
        iparm[0] = 1; /* No solver default */
        //iparm[1] = 2; /* Fill-in reordering from METIS */
        /* Numbers of processors, value of OMP_NUM_THREADS */
        iparm[2] = 1;
        //iparm[3] = 0; /* No iterative-direct algorithm */
        //iparm[4] = 0; /* No user fill-in reducing permutation */
        //iparm[5] = 0; /* Write solution into x */
        //iparm[6] = 0; /* Not in use */
        //iparm[7] = 2; /* Max numbers of iterative refinement steps */
        //iparm[8] = 0; /* Not in use */
        //iparm[9] = 13; /* Perturb the pivot elements with 1E-13 */
        //iparm[10] = 0; /* Use nonsymmetric permutation and scaling MPS */
        //iparm[11] = 0; /* Not in use */
        //iparm[12] = 0; /* Maximum weighted matching algorithm is switched-off
        //                * (default for symmetric). Try iparm[12] = 1 in case of
        //                *  inappropriate accuracy */
        //iparm[13] = 0; /* Output: Number of perturbed pivots */
        //iparm[14] = 0; /* Not in use */
        //iparm[15] = 0; /* Not in use */
        //iparm[16] = 0; /* Not in use */
        //iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */
        //iparm[18] = -1; /* Output: Mflops for LU factorization */
        //iparm[19] = 0; /* Output: Numbers of CG Iterations */
        maxfct = 1; /* Maximum number of numerical factorizations. */
        mnum = 1; /* Which factorization to use. */
        msglvl = 1; /* Print statistical information in file */
        error = 0; /* Initialize error flag */

        for (i = 0; i < 64; i++)
        {
            pt = IntPtr.Zero;
        }

        phase = 13;


        msglvl = 1;
        for (int j = 0; j < 2; j++)
        {
            double[] testA = new double;
            double[] testB = new double;
            error = 0;
            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                ref n, a.Doubles, ia, ja, perm, ref nrhs,
                iparm, ref msglvl, b.Doubles, testA, ref error);

            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                ref n, a.Doubles, ia, ja, perm, ref nrhs,
                iparm, ref msglvl, b.Doubles, testB, ref error);


            for (int k = 0; k < 2; k++)
            {
                if (testA != testB)
                {
                    Console.WriteLine("Diff");
                }
            }
        }

        return 0;
    }


    public unsafe class AlignedDoubleArrayPointer
    {
        GCHandle handle;
        public int Size { get; set; }
        double* doubles;

        public AlignedDoubleArrayPointer()
        {
            Size = 0;
        }

        public AlignedDoubleArrayPointer(double[] data)
        {
            CopyFrom(data);
        }

        public ulong Alignment
        {
            get
            {
                return 16;
            }
        }

        public double* Doubles
        {
            get
            {
                return doubles;
            }
        }

        public void Free()
        {
            if (handle.IsAllocated)
            {
                handle.Free();
            }
            Size = 0;
        }

        public void CheckSize(int requiredSize)
        {
            if (requiredSize > Size)
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }


                handle = GCHandle.Alloc(new double[requiredSize + 3], GCHandleType.Pinned);

                Size = requiredSize;
                ulong addr = new UIntPtr((double*)handle.AddrOfPinnedObject()).ToUInt64();
                ulong newAddr = (addr + (Alignment - 1)) & ~(Alignment - 1);
                doubles = (double*)new UIntPtr(newAddr).ToPointer();
            }
        }

        public void CopyFrom(double[] original)
        {
            CheckSize(original.Length);
            for (int i = 0; i < original.Length; i++)
            {
                doubles = original;
            }
        }

        public double this[int i]
        {
            get
            {
                return doubles;
            }
            set
            {
                doubles = value;
            }
        }

    }

}

namespace mkl
{
    /** Pardiso wrappers */
    public unsafe sealed class Pardiso
    {
        private Pardiso() { }

        public static int pardiso(IntPtr[] handle,
            ref int maxfct, ref int mnum,
            ref int mtype, ref int phase, ref int n,
            double* a, int[] ia, int[] ja, int[] perm,
            ref int nrhs, int[] iparm, ref int msglvl,
            double* b, double[] x, ref int error)
        {
            return PardisoNative.pardiso(handle,
                ref maxfct, ref mnum, ref mtype, ref phase, ref n,
                a, ia, ja, perm, ref nrhs, iparm, ref msglvl,
                b, x, ref error);
        }
    }

    /** Pardiso native declarations */
    [SuppressUnmanagedCodeSecurity]
    internal unsafe sealed class PardisoNative
    {
        private PardisoNative() { }

        [DllImport("libpardiso500-WIN-X86-64.dll", CallingConvention = CallingConvention.Cdecl,
             ExactSpelling = true, SetLastError = false)]
        internal static extern int pardiso([In, Out] IntPtr[] handle,
            ref int maxfct, ref int mnum,
            ref int mtype, ref int phase, ref int n,
            [In] double* a, [In] int[] ia, [In] int[] ja, [In] int[] perm,
            ref int nrhs, [In, Out] int[] iparm, ref int msglvl,
            [In, Out] double* b, [Out] double[] x, ref int error);
    }
}


 

0 Kudos
Ying_H_Intel
Employee
602 Views

Dear John,

Thanks for the reports. I will try to find the source code and upload them to the articles.

Attach one is the pardiso.cs sample.  I just try it, it seems work fine with MSVC 2010 X64 prompt windows.  The command line is as below.

Setting environment for using Microsoft Visual Studio 2010 x64 tools.

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>cd C:\Users\yhu5\Desktop\
mkl_issue\intel-mkl-c-23-examples

C:\Users\yhu5\Desktop\mkl_issue\intel-mkl-c-23-examples>"C:\Program Files (x86)\
Intel\Composer XE 2015\mkl\bin\mklvars.bat" intel64

C:\Users\yhu5\Desktop\mkl_issue\intel-mkl-c-23-examples>nmake

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Usage: nmake {ia32/intel64} MKLREDIST=path
set "CSCOPTS=/platform:x86" to run ia32 on Intel64 platform

C:\Users\yhu5\Desktop\mkl_issue\intel-mkl-c-23-examples>nmake intel64 MKREDIST=$
PATH

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Add path of the MKL redistributable to the path environment variable
        set path=%MKLREDIST%\intel64\mkl;%MKLREDIST%\intel64\compiler;%path%
Build and run examples
        nmake /a pardiso.exe

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Compile pardiso.cs
        csc  .\pardiso.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.18408
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

Run pardiso example
        pardiso.exe

=== PARDISO: solving a symmetric indefinite system ===
1-based array indexing is turned ON
PARDISO double precision computation is turned ON
METIS algorithm at reorder step is turned ON
Scaling is turned ON


Summary: ( reordering phase )
================

Times:
======
Time spent in calculations of symmetric matrix portrait (fulladj): 0.000022 s
Time spent in reordering of the initial matrix (reorder)         : 0.000125 s
Time spent in symbolic factorization (symbfct)                   : 0.000661 s
Time spent in allocation of internal data structures (malloc)    : 0.002399 s
Time spent in additional calculations                            : 0.000050 s
Total time spent                                                 : 0.003258 s

Statistics:
===========
Parallel Direct Factorization is running on 4 OpenMP

< Linear system Ax = b >
             number of equations:           8
             number of non-zeros in A:      18
             number of non-zeros in A (): 28.125000

             number of right-hand sides:    1

< Factors L and U >
             number of columns for each panel: 128
             number of independent subgraphs:  0
< Preprocessing with state of the art partitioning metis>
             number of supernodes:                    4
             size of largest supernode:               4
             number of non-zeros in L:                31
             number of non-zeros in U:                1
             number of non-zeros in L+U:              32

Reordering completed ...
Number of nonzeros in factors = 32
Number of factorization MFLOPS = 0
=== PARDISO is running in In-Core mode, because iparam(60)=0 ===
Percentage of computed non-zeros for LL^T factorization
 9
 19
 45
 96
 100


=== PARDISO: solving a symmetric indefinite system ===
Single-level factorization algorithm is turned ON


Summary: ( factorization phase )
================

Times:
======
Time spent in copying matrix to internal data structure (A to LU): 0.000000 s
Time spent in factorization step (numfct)                        : 0.002769 s
Time spent in allocation of internal data structures (malloc)    : 0.001192 s
Time spent in additional calculations                            : 0.000010 s
Total time spent                                                 : 0.003972 s

Statistics:
===========
Parallel Direct Factorization is running on 4 OpenMP

< Linear system Ax = b >
             number of equations:           8
             number of non-zeros in A:      18
             number of non-zeros in A (): 28.125000

             number of right-hand sides:    1

< Factors L and U >
             number of columns for each panel: 128
             number of independent subgraphs:  0
< Preprocessing with state of the art partitioning metis>
             number of supernodes:                    4
             size of largest supernode:               4
             number of non-zeros in L:                31
             number of non-zeros in U:                1
             number of non-zeros in L+U:              32
             gflop   for the numerical factorization: 0.000000

             gflop/s for the numerical factorization: 0.000025


Factorization completed ...

=== PARDISO: solving a symmetric indefinite system ===


Summary: ( solution phase )
================

Times:
======
Time spent in direct solver at solve step (solve)                : 0.000290 s
Time spent in additional calculations                            : 0.000623 s
Total time spent                                                 : 0.000913 s

Statistics:
===========
Parallel Direct Factorization is running on 4 OpenMP

< Linear system Ax = b >
             number of equations:           8
             number of non-zeros in A:      18
             number of non-zeros in A (): 28.125000

             number of right-hand sides:    1

< Factors L and U >
             number of columns for each panel: 128
             number of independent subgraphs:  0
< Preprocessing with state of the art partitioning metis>
             number of supernodes:                    4
             size of largest supernode:               4
             number of non-zeros in L:                31
             number of non-zeros in U:                1
             number of non-zeros in L+U:              32
             gflop   for the numerical factorization: 0.000000

             gflop/s for the numerical factorization: 0.000025


Solve completed ...

The solution of the system is:

 x [0] = -0.0418602012868094
 x [1] = -0.0034131241592791
 x [2] = 0.117250376805018
 x [3] = -0.11263957992318
 x [4] = 0.0241722444613714
 x [5] = -0.107633340356223
 x [6] = 0.198719673273585
 x [7] = 0.190382963551205
TEST PASSED


Best Regards,

Ying

0 Kudos
JohnNichols
Valued Contributor III
602 Views

Dear Ying:

 

Thank you very much.  It must be a pain having to take time out of a busy day to answer simple problems.

Have a nice day

John

0 Kudos
Ying_H_Intel
Employee
602 Views

Hi John, 

Hope the sample works for you.  I modify the article https://software.intel.com/en-us/articles/using-intel-mkl-in-your-c-program  and upload 2 sample there. 

Thanks

Ying 

0 Kudos
JohnNichols
Valued Contributor III
602 Views

Yes I now have them working - it is very nice.

I am not sure what we would do without INTEL, Steve and mecej4.

Look for an Ark I suppose.

JMN

0 Kudos
Max_V_1
Beginner
602 Views

Hi Ying,

The link in the article that you refer to is still broken. Any chance you can fix it or provide a working link here? I needed to see dgeev.cs - LAPACK part...

Max

0 Kudos
mecej4
Honored Contributor III
602 Views

I think that there is a new problem with the forum software.

I found yesterday that many text file attachments to posts in the Intel Visual Fortran for Windows forum, some of which worked fine a couple of days ago, and one attachment posted yesterday, lead to "Page not found" when I click on the links.

0 Kudos
Ying_H_Intel
Employee
602 Views

Hi Max, mecej4, 

Thanks for asking. I upload the example code here.  

All of them apply to the

License Agreement to Download

 

Intel Sample Source Code License Agreement

 

Thanks

Ying

0 Kudos
Max_V_2
Beginner
602 Views

Thank you Ying - it works here!

If the links to the downloads in original article on using MKL from C# could be fixed - that would certainly make like easier for many-many .Net developers...

Max

0 Kudos
Reply