Our hardware is Intel Xeon Phi so we are encouraged to get the most out of it by replacing hand-written linear algebra ops (e.g. square matrix multiplications) using Intel MKL.
The question is which should be the correct MKL usage for this case, as the problem of our matrices' rows not being contiguous in memory may forbid the usage of certain functions, e.g. cblas_dgemm.
Is this a use-case for sparse BLAS?
Example of matrix with non contiguous rows:
#include <iostream>
int main()
{
// construct this matrix:
//
// ( 1 2 3 )
// ( 4 5 6 )
const int NCOLS = 3;
// allocate two perhaps-not-contiguous blocks of memory
double *row1 = (double*)malloc(NCOLS * sizeof(double));
double *row2 = (double*)malloc(NCOLS * sizeof(double));
// initialize them to the desired values, i.e.
row1[0] = 1;
row1[1] = 2;
row1[2] = 3;
row2[0] = 4;
row2[1] = 5;
row2[2] = 6;
// allocate a block of two memory elements the size of a pointer
double **matrix = (double**)malloc(2 * sizeof(double*));
// set them to point to the two (perhaps-not-contiguous) previous blocks
matrix[0] = &row1[0];
matrix[1] = &row2[0];
// print
for (auto j=0; j<2; j++)
{
for (auto i=0; i<3; i++)
{
std::cout << matrix[j][i] << ",";
}
std::cout << "\n";
}
}