Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
6590 Discussions

fortran example for routine mkl_sparse_?_export_csr



I am looking for help about how to implement the mkl Inspector-Executor sparse routine "mkl_sparse_?_export_csr" in Fortran. I found the example in C but not in Fortran. In fact, I am using the Intel version 2017 where no example is given for this routine while I saw for version 2020, there is an example in Fortran f90.

Could anyone post the example here? I am confused by the input "rows_start" .. which is required as a pointer to array. No idea about how to implement this kind of pointer in Fortran.

Thank you in advance !


0 Kudos
5 Replies
Black Belt

There is an example, sparse_d_export_csr.f90, in the MKL examples\spblasf\source in the MKL2018  and later distributions.

This example was not present in MKL 2016, and the export routines are not present in the MKL 2016 libraries. The MKL 2018 example failed to be built with this older version of MKL.

I suspect that your MKL 2017 libraries do not contain the sparse matrix export routines either, but you can find out for yourself by using DUMPBIN.

In general, you should not expect to find newly added routines and capabilities in older versions of software. My recommendation is that you obtain the current version of MKL.


Thank you for your reply.

But the problem is I cannot update the version of Intel as I like since I am using my school's PC and all the softwares were installed by school's IT departement. They have indeed tested the compatibility  of this version 2017 with others (like Abaqus, IDE VS..) so this version is the most updated and stable for them..

In fact, what I am looking for is an example of the routine "mkl_sparse_?_export_csr". I am certain that this routine is included in the MKL library of version 2017 (I found the interface in the file "mkl_spblas.f90"), I can also run this routine in my codes, but the results confused me...

Maybe I didn't explain well. For this routine, the input "rows_start", "rows_end", "col_indx", "values" are all required to be a pointer to array.. This pointer is simple to be implemented using C (adress of parameter using &) but I cannot find out how to implement in Fortran. Actually, in the interface "mkl_spblas.f90", these parameters are declared as "integer/real, intent(inout), dimension(*) :: ...". I am not clear how to deal with this kind of declaration using a pointer.. (there is no "target" attribute..)

So if you don't have the example in hand, any explanation will also be appreciated !

Thank you in advance.


Black Belt

If you have a suitable version of MKL installed, there will be three zip files in the .../MKL/examples directory. You can copy the zip file to your own directory and extract the example that you want from it, or extract all the files in the zip if you prefer.

The terminology used ("pointer", "index", etc.) can be confusing, and the confusion is made worse by the choice of the MKL document writers to describe zero- and one-based indexing simultaneously. Furthermore, the two arrays pointerB and pointerE contain redundant information, but that was a design decision made by whoever originated the SparseBlas routines.

I suggest that you look at the example matrix and the "pointer" array values at

(scroll down till you see the heading "Storage Arrays for a Matrix in CSR Format")


@mecej4 Thanks for your reply.

I have studied the format CSR of sparse matrix and known the definition of its different parameters (pointerB, pointerE, etc).

I found finally the example and the updated interface in newer version of MKL (2019). In new interface, declarations are modified from (e.g. for rows_start) "integer, intent(inout), dimension(*) :: rows_start" to "type(c_ptr), intent(inout) :: rows_start" and so in the given example, we define "type(c_ptr) :: rows_start_c" and "integer, pointer :: rows_start_f(:) " and use the routine "c_f_pointer" to convert pointer from C to Fortran.

Well, maybe it's better to use a type "c_ptr" to achieve this export, but I really want to know how to use the older routine (I mean like in version 2017 I'm using, with the declaration "dimension(*)..." in interface). There must be a method, I suppose.. considering when you Intel genius guys were constructing this old routine.

Thank you for your attention.



follow this link, you may download the latest version of MKL for personal usage.