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

anyways for me to download the standalone mkl versions before the year of 2019 ?

huangwentao
New Contributor I
804 Views

Hi, I am using intel mkl 2024.2 now, and I found that the function "mkl_dcsrmultcsr" is no longer available.


However, I am working on a old project (year 2019), which depends on "mkl_dcsrmultcsr" for sparse matrix multiplication. I wonder if there is anyways to download the standalone mkl library for me to build this old project?

 

I am aware that 2024.2 allows me to do the multiplication with function "mkl_sparse_spmm", but this does not allow me to allocate memory for the result matrix manually. Thus, "mkl_dcsrmultcsr" is the only hope for me to achieve this goal in mkl.

 

Thanks.

0 Kudos
1 Solution
noffermans
Employee
589 Views

Great to hear that it compiles!

The routine only supports 1-based indexing, so you would need to add 1 to all your row and column indices. The output C matrix will be 1-based as well. This is easy to miss, but it is actually mentioned in the short description at the top of the doc page for the routine.

Hope this helps.

Best,
Nicolas

View solution in original post

0 Kudos
6 Replies
noffermans
Employee
779 Views

Hi @huangwentao ,

The mkl_?csrmultcsr APIs are marked as deprecated but they are still available in the 2024.2 version of the library and still documented in the Developer Reference:
Fortran: https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-fortran/2024-2/mkl-csrmultcsr.html
C: https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-2/mkl-csrmultcsr.html

Did you try to link and run your project with oneMKL 2024.2? Please let us know if you encounter any issue in doing so.

Best,
Nicolas

0 Kudos
huangwentao
New Contributor I
776 Views

Hi @noffermans ,

 

yes, already try to compile the project with 2024.2. but it says, 


"undefined reference to `mkl_dcsrmultcsr'"

 

I guess it does not work with 2024.2.

 

Regards,

Wentao

0 Kudos
noffermans
Employee
737 Views

This is probably due to an issue with the way the project is built and linked, because the routine is still available and defined in oneMKL 2024.2.
I would recommend checking the MKL's link line advisor for help with linking:
https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html


Note: you should see some warnings when using deprecated APIs:

warning: 'mkl_dcsrmultcsr' is deprecated [-Wdeprecated-declarations]

 or

note: 'mkl_dcsrmultcsr' has been explicitly marked deprecated here 

 but it does not affect functionality.

Best,
Nicolas

0 Kudos
huangwentao
New Contributor I
620 Views

Thank you, @noffermans 

 

After checking the link-line-advisor, I have successfully built the code.

 

However, I found that the code execution is not correct, I am not sure if it is due to the deprecated routine problem. Would you mind having a glance of the following C code, "mytest.c" and see what is wrong?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mkl.h"

int main() {
	// Matrix A in CSR format (3x5)
	MKL_INT rowsA = 2, colsA = 3;
	MKL_INT rowptrA[2 + 1] = {0, 2, 3}; // Row pointers for matrix A in CSR format
	MKL_INT colindA[3] = {0, 1, 2}; // Column indices of non-zero elements
	double valuesA[3] = {1.0, 2.0, 3.0}; // Non-zero values

	// Matrix B in CSR format (5x7)
	MKL_INT rowsB = 3, colsB = 4;
	MKL_INT rowptrB[3 + 1] = {0, 1, 3, 4}; // Row pointers for matrix B in CSR format
	MKL_INT colindB[4] = {0, 1, 2, 3}; // Column indices of non-zero elements
	double valuesB[4] = {4.0, 5.0, 6.0, 7.0}; // Non-zero values


	/**
	// Output the result in CSR format
	printf("Result matrix A in CSR format:\n");

	printf("Row pointers: ");
	for (int i = 0; i <= rowsA; i++) {
		printf("%lld ", rowptrA[i]);
	}
	printf("\nColumn indices: ");
	for (int i = 0; i < rowptrA[rowsA]; i++) {
		printf("%lld ", colindA[i]);
	}
	printf("\nValues: ");
	for (int i = 0; i < rowptrA[rowsA]; i++) {
		printf("%f ", valuesA[i]);
	}
	printf("\n\n");


	// Output the result in CSR format
	printf("Result matrix B in CSR format:\n");

	printf("Row pointers: ");
	for (int i = 0; i <= rowsB; i++) {
		printf("%lld ", rowptrB[i]);
	}
	printf("\nColumn indices: ");
	for (int i = 0; i < rowptrB[rowsB]; i++) {
		printf("%lld ", colindB[i]);
	}
	printf("\nValues: ");
	for (int i = 0; i < rowptrB[rowsB]; i++) {
		printf("%f ", valuesB[i]);
	}
	printf("\n\n");
	*/

	// Matrix C will be the result (3x7)
	MKL_INT rowsC = rowsA, colsC = colsB;
	// Pre-allocate space for C in CSR format
	MKL_INT rowptrC[rowsC + 1]; // Row pointers for C
	memset(rowptrC, 0, sizeof(MKL_INT) * (rowsC+1));
	MKL_INT request = 1;
	MKL_INT sort = 7; // don't sort anything
	MKL_INT info = 0; // output info flag
	mkl_dcsrmultcsr((char*)"N", &request, &sort,
		&rowsA, &colsA, &colsB,
		valuesA, colindA, rowptrA, 
		valuesB, colindB, rowptrB, 
		NULL, NULL, rowptrC,
		NULL, &info
	);
	printf("info-values: %lld\n", info);
	MKL_INT nnzC = rowptrC[rowsC] - 1;
	MKL_INT* colindC = (MKL_INT*) malloc( sizeof(MKL_INT) * nnzC );
	double* valuesC = (double*) malloc( sizeof(double) * nnzC );
	memset(colindC, 0, sizeof(MKL_INT) * nnzC);
	memset(valuesC, 0, sizeof(double) * nnzC);

	request = 2;
	sort = 8;
	mkl_dcsrmultcsr((char*)"N", &request, &sort,
		&rowsA, &colsA, &colsB,
		valuesA, colindA, rowptrA, 
		valuesB, colindB, rowptrB, 
		valuesC, colindC, rowptrC,
		NULL, &info
	);
	printf("info-values: %lld\n", info);

	// Output the result in CSR format
	printf("Result matrix C in CSR format:\n");

	printf("Row pointers: ");
	for (int i = 0; i <= rowsC; i++) {
		printf("%lld ", rowptrC[i]);
	}
	printf("\nColumn indices: ");
	for (int i = 0; i < rowptrC[rowsC]; i++) {
		printf("%lld ", colindC[i]);
	}
	printf("\nValues: ");
	for (int i = 0; i < rowptrC[rowsC]; i++) {
		printf("%f ", valuesC[i]);
	}
	printf("\n");


	free(colindC);
	free(valuesC);

	return 0;
}

 

I built this project with the following makefile,

CC = gcc

MKLROOT = /opt/intel/oneapi/mkl/2024.2
MKL_FLAGS_GCC = -DMKL_ILP64 \
				-I"${MKLROOT}/include" \
				-m64 -L${MKLROOT}/lib/intel64 \
				-Wl,-rpath,${MKLROOT}/lib/intel64 \
				-lmkl_intel_ilp64 \
				-lmkl_sequential -lmkl_core -lpthread -lm -ldl

mytest: mytest.c
	$(CC) -o $@ $< $(MKL_FLAGS_GCC) -Wall

clean:
	rm mytest

 

Thank you, and look forward to your reply.

 

Regards,

Wentao

 

0 Kudos
noffermans
Employee
590 Views

Great to hear that it compiles!

The routine only supports 1-based indexing, so you would need to add 1 to all your row and column indices. The output C matrix will be 1-based as well. This is easy to miss, but it is actually mentioned in the short description at the top of the doc page for the routine.

Hope this helps.

Best,
Nicolas

0 Kudos
huangwentao
New Contributor I
568 Views

Thank you @noffermans 

 

I forgot to check the indexing. I can continue with my work now  : )

 

Regards,

Wentao

Reply