I would like to use MKL to solve a sparse linear system. I chose the DSS (Direct Sparse Solver) interface, which implements the following steps:
//(1).define the non-zero structure of the matrix
dss_define_structure(handle, sym, rowIndex, nRows, nCols, columns, nNonZeros);
//(2).reorder the matrix
dss_reorder(handle, opt, 0);
//(3).factor the matrix
dss_factor_real(handle, type, values);
//(4).get the solution vector
dss_solve_real(handle, opt, rhs, nRhs, solValues);
//(5).deallocate solver storage
dss_delete(handle, opt);
According to my test, the DSS uses a column-major ordering. That means
//column = 3
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
is equivalent to
{{1, 6, 11},
{2, 7, 12},
{3, 8, 13},
{4, 9, 14}
{5, 10, 15}}
For instance, there is a sparase linear system $\mathbf A_{5\times 5}\mathbf X_{5\times 3}=\mathbf B_{5\times 3}$
where $\mathbf A$ is symmetric sparse array
//A stored with CSR3 format
rowIndex = { 0, 5, 6, 7, 8, 9 };
columns = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
values = { 9, 1.5, 6, .75, 3, 0.5, 12, .625, 16 };
//B
rhs[5*3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
//X
solValues[15]
By calling the above DSS interface, the solValues
is
{-326.333, 983, 163.417, 398, 61.5,
-844.667, 2548, 423, 1028, 159,
-1363, 4113, 682.583, 1658, 256.5}
Namely
$$ \mathbf X_{5\times 3}=\left( \begin{array}{ccc} -326.333 & -844.667 & -1363 \\ 983 & 2548 & 4113 \\ 163.417 & 423 & 682.583 \\ 398 & 1028 & 1658 \\ 61.5 & 159 & 256.5 \\ \end{array} \right) $$
In my application, the matrix is row-major. How to deal with this problem?