Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
6680 Discussions

Should I reuse my CSR-format matrix handles?

Hodara__Joachim1
Beginner
422 Views

Hi everyone,

 

How cheap is it to create/destroy a handle for a CSR-format matrix? I am running an iterative code, and the same operation will be repeated many times on the same matrix (although its content will change over time). Should I call mkl_sparse_?_create_csr once at the beginning, reuse the same handle every time, and eventually call mkl_sparse_destroy at the end of the run, or is the cost of creating/destroying the handle negligible? (is the memory coming from a pre-allocated buffer?) It would sure be cleaner to create/destroy the handle every time for me, but I want to make sure I will not pay a stiff price for it.

 

Thanks,

Joachim

 

EDIT: I just discovered mkl_sparse_optimize. In my case, the content of the matrix will change, but not its sparse structure. Does it mean I should create a handle, perform the optimization and keep the handle alive?

0 Kudos
6 Replies
ShanmukhS_Intel
Moderator
387 Views

Hi,


Thank you for posting on Intel Communities.


Could you please check if there is significant performance difference in both cases mentioned by you. We would recommend to try VTune Profiler analysis on your application and check if this is impacting the performance of your application and let us know if you notice any discrepancy.


You could refer to below link for help regarding VTune Profiler.


https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top.html


Best Regards,

Shanmukh.SS


Hodara__Joachim1
Beginner
375 Views

Hi,

 

Thank you, but I'd rather know the answer before I spend many hours implementing both solutions. I just want to know if the matrix handle is some cheap construct like a std::string_view or if its construction/destruction requires memory allocations and other expensive operations.

 

Best regards,

Joachim

Kirill_V_Intel
Employee
365 Views

Hi Joachim,

The answer to your question depends on whether you do any calls like mkl_sparse_set_<...>_hint + mkl_sparse_optimize() or not.

If you don't, handle is a thin wrapper around the data you provided in create routine and the create-destroy is cheap.

If you do, then MKL can internally take a decision to convert a matrix to some different format and will store all the optimized data inside the handle. In this case, create is cheap but optimize() can create a lot of extra data and destroy won't be cheap (at the very least doing create-optimize-destroy many times will cause a lot of memory allocation/deallocation).

I hope this helps.

Best,
Kirill

ShanmukhS_Intel
Moderator
347 Views

Hi,


Reminder:

Has the information provided helped? Kindly let us know if we could close this thread at end.


Best Regards,

Shanmukh.SS


Hodara__Joachim1
Beginner
340 Views

Very helpful, I got the info I was looking for. Thanks!

ShanmukhS_Intel
Moderator
331 Views

Hi,


Glad to know that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Best Regards,

Shanmukh.SS


Reply