Hi All,
I think that the result of "mkl_sparse_d_mm" is incorrect as evident for the following code. The code basically tries to multiply the Identity matrix stored in CSR format with a dense matrix and checks whether the result and the input matrix are the same. This also the case in ROW MAJOR layout as well.
int main() { MKL_INT n = 5; MKL_INT rows_start[5] = {0,1,2,3,4}; MKL_INT rows_end[5] = {1,2,3,4,5}; MKL_INT col_indx[5] = {0,1,2,3,4}; double values[5] = {1,1,1,1,1}; sparse_matrix_t csrA = NULL; sparse_index_base_t indexing; struct matrix_descr descr_type_gen; descr_type_gen.type = SPARSE_MATRIX_TYPE_GENERAL; mkl_sparse_d_create_csr ( &csrA, SPARSE_INDEX_BASE_ZERO, n, n, rows_start, rows_end, col_indx, values); MKL_INT row, col; sparse_index_base_t indextype; MKL_INT * bi, *ei, *indx; double *rv; mkl_sparse_d_export_csr(csrA, &indextype, &row, &col, &bi, &ei, &indx, &rv); printf("Input csr matrix\n"); for(long i=0; i < n; i++) { printf("%ld ----> ",i); for(long l = 0; l < n; l++) { bool flag = false; for(long j=bi[i]; j < ei[i]; j++) { if(indx[j] == l) { flag = true; printf("%.0lf ",rv[j]); break; } } if(!flag) printf("%d ",0); } printf("\n"); } double *matrix = (double *) mkl_malloc ( n*2*sizeof(double), ALIGN); double *result = (double *) mkl_calloc ( n*2, sizeof(double), ALIGN); for(long i=0; i < n; i++) { matrix[i] = i+1; matrix[i + n] = n-i; } printf("Input dense matrix\n"); for(long i=0; i < n; i++) { for(long j=0 ; j < 2; j++) { printf("%.2lf ", matrix[i + j*n]); } printf("\n"); } mkl_sparse_d_mm( SPARSE_OPERATION_NON_TRANSPOSE, 1, csrA, descr_type_gen, SPARSE_LAYOUT_COLUMN_MAJOR, matrix, 2, n, 0, result, n); printf("Outpur result matrix\n"); for(long i=0; i < n; i++) { for(long j=0 ; j < 2; j++) { printf("%.2lf ", result[i + j*n]); } printf("\n"); } mkl_free(matrix); mkl_free(result); return 0; }
The output of the above code is :-
Input csr matrix 0 ----> 1 0 0 0 0 1 ----> 0 1 0 0 0 2 ----> 0 0 1 0 0 3 ----> 0 0 0 1 0 4 ----> 0 0 0 0 1 Input dense matrix 1.00 5.00 2.00 4.00 3.00 3.00 4.00 2.00 5.00 1.00 Output result matrix 1.00 5.00 0.00 0.00 1.00 5.00 0.00 0.00 2.00 4.00
I run the above with the following options:
icc -I. -I/opt/intel/compilers_and_libraries_2019.3.199/linux/mkl/include -DMKL_ILP64 -Wall -O3 -qopenmp -qopenmp-simd -mkl=parallel -std=c++11 -Wno-attributes mkl_sparse_d_mm.cpp -o mkl_sparse_mm -L/opt/intel/compilers_and_libraries_2019.3.199/linux/mkl/lib/intel64_lin -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -ldl
and I also tried with a different intel mkl version as follows:
icc -I. -I/opt/intel/compilers_and_libraries_2018.5.274/linux/mkl/include -DMKL_ILP64 -Wall -O3 -qopenmp -qopenmp-simd -mkl=parallel -std=c++11 -Wno-attributes mkl_sparse_d_mm.cpp -o mkl_sparse_mm -L/opt/intel/compilers_and_libraries_2018.5.274/linux/mkl/lib/intel64_lin -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -ldl