Using Intel sblas functions to translate coo to csr matrix
If you want to replace this you can start by checking sorting algorithms: https://www.mjr19.org.uk/IT/sorts/
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | nb_state_vars | |||
| type(coo_csr_t(:)), | intent(inout), | allocatable, target | :: | arr |
subroutine coo_to_csr(nb_state_vars,arr) !! Using Intel sblas functions to translate coo to csr matrix !! !! If you want to replace this you can start by checking sorting algorithms: !! https://www.mjr19.org.uk/IT/sorts/ use mkl_spblas use iso_c_binding integer, intent(in) :: nb_state_vars type(coo_csr_t(:)), allocatable, target, intent(inout) :: arr real(dp), pointer :: coo_ptr_mold(:) type(sparse_matrix_t) :: coo_mkl, csr_mkl integer :: stat, nbRow, nbCol, index_base, nbNonZeros type(c_ptr) :: row_cptr, col_cptr, val_cptr, dummy_cptr, coo_cptr nbNonZeros = size(arr%coo_col) ! pretend that array of pointers is array of doubles coo_cptr = c_loc(arr%coo_ptr) call c_f_pointer(coo_cptr,coo_ptr_mold,[nbNonZeros]) stat = mkl_sparse_d_create_coo(coo_mkl, sparse_index_base_one, nb_state_vars, & nb_state_vars, nbNonZeros, arr%coo_row, arr%coo_col, coo_ptr_mold) call check_status(stat,'In mkl_sparse_d_create_coo error returned: ') stat = mkl_sparse_convert_csr(coo_mkl, sparse_operation_non_transpose, csr_mkl) call check_status(stat,'In mkl_sparse_convert_csr error returned: ') stat = mkl_sparse_d_export_csr(csr_mkl, index_base, nbRow, nbCol, row_cptr, & dummy_cptr, col_cptr, val_cptr) call check_status(stat,'In mkl_sparse_d_export_csr error returned: ') call c_f_pointer(row_cptr,arr%csr_row,[nb_state_vars+1]) ! last value is number of non zeros + 1 call c_f_pointer(col_cptr,arr%csr_col,[nbNonZeros]) call c_f_pointer(val_cptr,arr%csr_ptr,[nbNonZeros]) end subroutine coo_to_csr