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

Behavior of mkl_sparse_d_export_csr in different versions

Robin_T_
Novice
1,297 Views

Hello,

 

I have a code that runs perfectly fine on ifort version 19.0.4.243. Now I want to run it on another computer with ifort version 17.0.2.

I get the error messages

error #6633: The type of the actual argument differs from the type of the dummy argument.   [NUNK]
    error = mkl_sparse_d_export_csr (hdl, indexing, nunk, nunk, INEM_C, INEM_end_C, JNEM_C, &
----------------------------------------------------^
error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic.   [ROWS_START]
    error = mkl_sparse_d_export_csr (hdl, indexing, nunk, nunk, INEM_C, INEM_end_C, JNEM_C, &
------------^

and similar for the other variables. Has the behavior of mkl_sparse_d_export_csr changed between these versions? Where would the older version be documented, preferably with an example?

0 Kudos
1 Solution
Gennady_F_Intel
Moderator
1,257 Views

Hi Robin,

We confirmed the issue with mkl_spblas.f90 header file.

The trivial fix of this case is replacing this header file from version 2020/2019.

Applying this workaround you could able to compile and link this example (sparse_d_export_csr.f90) against MKL 2017.

And it works w/o problems.

Thanks,

Gennady


View solution in original post

6 Replies
Gennady_F_Intel
Moderator
1,287 Views

The MKL ensures the compatibility between versions. Regarding to this case:

I see no differences between 2017.4 and the latest 2020.2 versions of Intel MKL:

here are the API ( check  the mkl_version.h mkl_spblas.h  header files)

2017

#define __INTEL_MKL__ 2017

#define __INTEL_MKL_MINOR__ 0

#define __INTEL_MKL_UPDATE__ 4

    sparse_status_t mkl_sparse_d_export_csr( const sparse_matrix_t  source,

                                             sparse_index_base_t    *indexing,      /* indexing: C-style or Fortran-style */

                                             MKL_INT    *rows,

                                             MKL_INT    *cols,

                                             MKL_INT    **rows_start,

                                             MKL_INT    **rows_end,

                                             MKL_INT    **col_indx,

                                             double     **values );

MKL 2020

#define __INTEL_MKL__ 2020

#define __INTEL_MKL_MINOR__ 0

#define __INTEL_MKL_UPDATE__ 2

 

    sparse_status_t mkl_sparse_d_export_csr( const sparse_matrix_t  source,

                                             sparse_index_base_t    *indexing,      /* indexing: C-style or Fortran-style */

                                             MKL_INT                *rows,

                                             MKL_INT                *cols,

                                             MKL_INT                **rows_start,

                                             MKL_INT                **rows_end,

                                             MKL_INT                **col_indx,

                                             double                 **values );

0 Kudos
Gennady_F_Intel
Moderator
1,285 Views

You may also check two C  examples (sparse_spmm.c sparse_spmmd.c) from mklroot/examples/spblasc/source/ folders

0 Kudos
Robin_T_
Novice
1,276 Views

Dear Gennady,

 

Thank you for your reply.

I am working on Fortran, however, so the relevant files should be mkl_spblas.f90

In the 19.0.4.243 version, it looks like

        FUNCTION MKL_SPARSE_D_EXPORT_CSR(source,indexing,rows,cols,rows_start,rows_end,col_indx,values) &
                 BIND(C, name='MKL_SPARSE_D_EXPORT_CSR')
            USE, INTRINSIC :: ISO_C_BINDING , ONLY : C_INT, C_DOUBLE, C_PTR
            IMPORT SPARSE_MATRIX_T
            TYPE(SPARSE_MATRIX_T), INTENT(IN) :: source
            INTEGER(C_INT), INTENT(INOUT) :: indexing
            INTEGER       , INTENT(INOUT) :: rows
            INTEGER       , INTENT(INOUT) :: cols
            TYPE(C_PTR)   , INTENT(INOUT) :: rows_start
            TYPE(C_PTR)   , INTENT(INOUT) :: rows_end
            TYPE(C_PTR)   , INTENT(INOUT) :: col_indx
            TYPE(C_PTR)   , INTENT(INOUT) :: values
            INTEGER(C_INT) MKL_SPARSE_D_EXPORT_CSR
        END FUNCTION

In the 17.0.2 version, it looks like

        FUNCTION MKL_SPARSE_D_EXPORT_CSR(source,indexing,rows,cols,rows_start,rows_end,col_indx,values) &
                 BIND(C, name='MKL_SPARSE_D_EXPORT_CSR')
            USE, INTRINSIC :: ISO_C_BINDING , ONLY : C_INT, C_DOUBLE
            IMPORT SPARSE_MATRIX_T
            TYPE(SPARSE_MATRIX_T), INTENT(IN) :: source
            INTEGER(C_INT)      , INTENT(INOUT) :: indexing
            INTEGER(C_INT)      , INTENT(INOUT) :: rows
            INTEGER(C_INT)      , INTENT(INOUT) :: cols
            INTEGER, INTENT(INOUT), DIMENSION(*) :: rows_start
            INTEGER, INTENT(INOUT), DIMENSION(*) :: rows_end
            INTEGER, INTENT(INOUT), DIMENSION(*) :: col_indx
            REAL(C_DOUBLE), INTENT(INOUT), DIMENSION(*) :: values
            INTEGER(C_INT) MKL_SPARSE_D_EXPORT_CSR
        END FUNCTION

An example is given in sparse_d_export_csr.f90 for the 19.0.4.243 version. For the 17.0.2 version, this example does not exist.

So, there definitely is some discrepancy between the versions. But I do not know how to make the function work on version 17.0.2 because of the lack of an example.

If you could give an example or let me know what I have to change in sparse_d_export_csr.f90 to make it work on version 17.0.2, that would be very appreciated.

0 Kudos
Robin_T_
Novice
1,272 Views

If I compile and run the example sparse_d_export_csr.f90 under v 17, using

ifort -fpp -I$MKLROOT/include -w $MKLROOT/include/mkl_spblas.f90 -c -o mkl_spblas.o
ifort -fpp -I$MKLROOT/include -w source/sparse_d_export_csr.f90 -c -o sparse_d_export_csr.o
ifort -fpp -I$MKLROOT/include -w sparse_d_export_csr.o mkl_spblas.o -o sparse_d_export.exe -mkl -liomp5 -lm
./sparse_d_export.exe 

It works fine.

Then I changed sparse_d_export_csr.f90 to

 

PROGRAM EXPORT_CSR

    USE MKL_SPBLAS
    USE ISO_C_BINDING
    IMPLICIT NONE
!   *****************************************************************************
!   Sparse representation of the matrices A and B:
!   *****************************************************************************
    INTEGER, ALLOCATABLE :: csrColInd(:), csrRowPtr(:)
    DOUBLE PRECISION, ALLOCATABLE :: csrVal(:)
!   CSR matrix structure
    TYPE(SPARSE_MATRIX_T) csrA, csrB
!   Variables used for exporting sparse matrix
    INTEGER(C_INT) :: indexing, nrows, ncols
    integer, allocatable :: rows_start(:), rows_end(:), col_indx(:)
    real(C_DOUBLE), allocatable :: values(:)
!   *****************************************************************************
!   Declaration of local variables:
!   *****************************************************************************
    INTEGER M, N, NNZ, i, j, info
    M = 5
    NNZ = 13
    ALLOCATE(csrColInd(NNZ))
    ALLOCATE(csrRowPtr(M+1))
    ALLOCATE(csrVal(NNZ))
    csrVal = (/ 1.0,-1.0,-3.0,-2.0,5.0,4.0,6.0,4.0,-4.0,2.0,7.0,8.0,-5.0 /)
    csrColInd = (/ 0,1,3,0,1,2,3,4,0,2,3,1,4 /)
    csrRowPtr = (/ 0,    3,  5,    8,   11,  13 /)

    print*,'EXAMPLE PROGRAM FOR MKL_SPARSE_D_EXPORT_CSR'
    print*,'---------------------------------------------------'
    print*,'Input matrix A:'
    do i = 1, M
        print*,'row #',i
        do j = csrRowPtr(i)+1, csrRowPtr(i+1)
            print*,csrColInd(j),csrVal(j)
        enddo
    enddo

!   Create CSR matrix
    info = MKL_SPARSE_D_CREATE_CSR(csrA,SPARSE_INDEX_BASE_ZERO,M,M,csrRowPtr(1),csrRowPtr(2),csrColInd,csrVal)

!   Compute B = A*A
    info = MKL_SPARSE_SPMM(SPARSE_OPERATION_NON_TRANSPOSE, csrA, csrA, csrB)

!   Export CSR matrix
    allocate (rows_start(m))
    allocate (rows_end(m))
    allocate (col_indx(nnz))
    allocate (values(nnz))
    rows_start = 0
    rows_end = 0
    col_indx = 0
    values = 0.d0
    info = MKL_SPARSE_D_EXPORT_CSR(csrB, indexing, nrows, ncols, rows_start, rows_end, col_indx, values)

!   Printing resulting matrix
    print*,'---------------------------------------------------'
    print*,'Output matrix B = A*A:'
    do i = 1, nrows
        print*,'row #',i
        do j = rows_start(i)+1, rows_end(i)
            print*,col_indx(j),values(j)
        enddo
    enddo

!   Release internal representation of CSR matrix
    info = MKL_SPARSE_DESTROY(csrA)
    info = MKL_SPARSE_DESTROY(csrB)

    print*,'---------------------------------------------------'

END PROGRAM EXPORT_CSR

and tried running it using the same commands, but I get

forrtl: severe (408): fort: (2): Subscript #1 of the array COL_INDX has value 7610881 which is greater than the upper bound of 13

Image              PC                Routine            Line        Source             
sparse_d_export.e  0000000000410FF6  Unknown               Unknown  Unknown
sparse_d_export.e  0000000000405D48  MAIN__                    103  sparse_d_export_csr.f90
sparse_d_export.e  0000000000402EDE  Unknown               Unknown  Unknown
libc-2.17.so       00002AAAAF77A3D5  __libc_start_main     Unknown  Unknown
sparse_d_export.e  0000000000402DE9  Unknown               Unknown  Unknown

I don't know how to continue from here.

0 Kudos
Gennady_F_Intel
Moderator
1,258 Views

Hi Robin,

We confirmed the issue with mkl_spblas.f90 header file.

The trivial fix of this case is replacing this header file from version 2020/2019.

Applying this workaround you could able to compile and link this example (sparse_d_export_csr.f90) against MKL 2017.

And it works w/o problems.

Thanks,

Gennady


Gennady_F_Intel
Moderator
1,247 Views

This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only


0 Kudos
Reply