Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 190

mkl_ddnscsr problems

$
0
0

Hello everyone

I am trying to use the ddnscsr to build the arrays a, ia, ja which will then be used for the pardiso or other routines which need CSR formatting. 

Basically to make sure I understand calling the routine I have been trying to implement it on the nonsymmetric matrix listed in the sparse storage format page, but it isnt working and I cannot figure out why.

    //
    //                 |   1    -1    0   -3   0   |
    //                 |  -2     5    0    0   0   |
    //   A    =           |   0     0    4    6   4   |
    //                 |  -4     0    2    7   0   |
    //                 |   0     8    0    0   -5  |
    //
    //  

    vector<vector<double>> A(5, vector<double>(5, 0));

    A[0][0] = 1.0;
    A[0][1] = -1.0;
    A[0][2] = 0.0;
    A[0][3] = -3.0;
    A[0][4] = 0.0;

    A[1][0] = -2.0;
    A[1][1] = 5.0;
    A[1][2] = 0.0;
    A[1][3] = 0.0;
    A[1][4] = 0.0;

    A[2][0] = 0.0;
    A[2][1] = 0.0;
    A[2][2] = 4.0;
    A[2][3] = 6.0;
    A[2][4] = 4.0;

    A[3][0] = -4.0;
    A[3][1] = 0.0;
    A[3][2] = 2.0;
    A[3][3] = 7.0;
    A[3][4] = 0.0;

    A[4][0] = 0.0;
    A[4][1] = 8.0;
    A[4][2] = 0.0;
    A[4][3] = 0.0;
    A[4][4] = -5.0;

    // ia[5] = {0, 3, 5, 8, 11, 14}
    // ja[13] = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4}
    // a[13] = {1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, -5}

            double *solution, *adns, *a, *b, *x;
            int rows, cols, c, i, j, k;
            MKL_INT m, n, lda, info;
            lda = 1;
            m = 5;
            n = m;
            int nzmax = 13;

            adns = (double*)mkl_malloc(nzmax*sizeof(double),16);
            if (adns == NULL) 
            {
                cout << ">>> error allocating adns"<< endl;
                return (0);
            }
            a = (double*)mkl_malloc(nzmax*sizeof(double),16);
            if (a == NULL) 
            {
                cout << ">>> error allocating a"<< endl;
                return (0);
            }

            MKL_INT *ia, *ja;
            ia = (MKL_INT *)mkl_malloc((m + 1)*sizeof(MKL_INT),16);
            if (ia == NULL) 
            {
                cout << ">>> error allocating a"<< endl;
                return (0);
            }
            ja = (MKL_INT*)mkl_malloc(nzmax*sizeof(MKL_INT),16);
            if (ja == NULL) 
            {
                cout << ">>> error allocating a"<< endl;
                return (0);
            }

            /*    Building input parameters for pardiso()    */
            /*    adns - array */
            c = 0;
            for (rows=0; rows<m; rows++) 
            {
                for (cols=0; cols<n; cols++) 
                {
                    if(A[rows][cols] != 0)
                    {
                        adns[c] = A[rows][cols];
                        c++;
                    }
                }
            }

            MKL_INT *job;
            job = (MKL_INT*)mkl_malloc((m + 1)*sizeof(MKL_INT),16);
            if (ja == NULL) 
            {
                cout << ">>> error allocating a"<< endl;
                return (0);
            }
            job[0] = 0;
            job[1] = 0;
            job[2] = 0;
            job[3] = 2;
            job[4] = 13;
            job[5] = 3;

            mkl_ddnscsr(job, &m, &n, adns, &lda, a, ja, ia, &info);

 

Here is my whole code I put together. the "A" matrix is the simple 5 X 5 matrix as shown above, and I even commented out the correct format as show, but for some reason it will not print out the a, ja, and ia arrays properly. Currently, the info = 2 and I cannot see why it is failing on the second row... please someone shed some light.

I have also attached the current output from this code.


Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>