Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions src/sparse/stdlib_sparse_spmv.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,134 @@ module stdlib_sparse_spmv
end subroutine
#:endfor
end interface

!! Version experimental
!!
!! Apply the COO sparse matrix-vector product $$y = \alpha * op(M) * x + \beta * y $$
!! [Specifications](../page/specs/stdlib_sparse.html#spmv)
interface spmv_coo
#:for k1, t1, s1 in (KINDS_TYPES)
#:for rank in RANKS
module subroutine spmv_coo_sub_${rank}$d_${s1}$(data, index, nnz, storage, vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: index(:,:)
integer, intent(in) :: storage
integer(ilp), intent(in) :: nnz
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
end subroutine
#:endfor
#:endfor
end interface

!! Version experimental
!!
!! Apply the CSC sparse matrix-vector product $$y = \alpha * op(M) * x + \beta * y $$
!! [Specifications](../page/specs/stdlib_sparse.html#spmv)
interface spmv_csc
#:for k1, t1, s1 in (KINDS_TYPES)
#:for rank in RANKS
module subroutine spmv_csc_sub_${rank}$d_${s1}$(data,colptr,row,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: colptr(:) !! matrix column pointer
integer(ilp), intent(in) :: row(:) !! matrix row pointer
integer(ilp), intent(in) :: nnz !! number of non-zero values
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage !! storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
end subroutine
#:endfor
#:endfor
end interface

!! Version experimental
!!
!! Apply the CSR sparse matrix-vector product $$y = \alpha * op(M) * x + \beta * y $$
!! [Specifications](../page/specs/stdlib_sparse.html#spmv)
interface spmv_csr
#:for k1, t1, s1 in (KINDS_TYPES)
#:for rank in RANKS
module subroutine spmv_csr_sub_${rank}$d_${s1}$(data,col,rowptr,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: col(:) !! matrix column pointer
integer(ilp), intent(in) :: rowptr(:) !! matrix row pointer
integer(ilp), intent(in) :: nnz !! number of non-zero values
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage !! storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
end subroutine
#:endfor
#:endfor
end interface

!! Version experimental
!!
!! Apply the ELL sparse matrix-vector product $$y = \alpha * op(M) * x + \beta * y $$
!! [Specifications](../page/specs/stdlib_sparse.html#spmv)
interface spmv_ell
#:for k1, t1, s1 in (KINDS_TYPES)
#:for rank in RANKS
module subroutine spmv_ell_sub_${rank}$d_${s1}$(data,index,mnz_p_row,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:,:)
integer(ilp), intent(in) :: index(:,:)
integer(ilp), intent(in) :: mnz_p_row
integer(ilp), intent(in) :: nnz
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
end subroutine
#:endfor
#:endfor
end interface

!! Version experimental
!!
!! Apply the SELLC sparse matrix-vector product $$y = \alpha * op(M) * x + \beta * y $$
!! [Specifications](../page/specs/stdlib_sparse.html#spmv)
interface spmv_sellc
#:for k1, t1, s1 in (KINDS_TYPES)
module subroutine spmv_sellc_sub_${s1}$(data,ia,ja,cs,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
!! This algorithm was gracefully provided by Ivan Privec and adapted by Jose Alves
${t1}$, intent(in) :: data(:,:)
integer(ilp), intent(in) :: ia(:)
integer(ilp), intent(in) :: ja(:,:)
integer, intent(in) :: cs
integer(ilp), intent(in) :: nnz
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage
${t1}$, intent(in) :: vec_x(:)
${t1}$, intent(inout) :: vec_y(:)
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
end subroutine
#:endfor
end interface

public :: spmv
public :: spmv_coo
public :: spmv_csc
public :: spmv_csr
public :: spmv_ell
public :: spmv_sellc

end module
20 changes: 17 additions & 3 deletions src/sparse/stdlib_sparse_spmv_coo.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ contains
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op

call spmv_coo_sub_${rank}$d_${s1}$(matrix%data, matrix%index, matrix%nnz, matrix%storage, &
vec_x,vec_y,alpha,beta,op)

end subroutine

module subroutine spmv_coo_sub_${rank}$d_${s1}$(data,index,nnz,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: index(:,:) !! Matrix coordinates index(2,nnz)
integer(ilp), intent(in) :: nnz !! number of non-zero values
integer, intent(in) :: storage !! storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
${t1}$ :: alpha_
character(1) :: op_
integer(ilp) :: col_index, k, row_index
Expand All @@ -33,7 +49,6 @@ contains
vec_y = zero_${s1}$
endif

associate( data => matrix%data, index => matrix%index, storage => matrix%storage, nnz => matrix%nnz )
select case(op_)
case(sparse_op_none)
if(storage == sparse_full) then
Expand Down Expand Up @@ -92,10 +107,9 @@ contains
end if
#:endif
end select
end associate
end subroutine

#:endfor
#:endfor

end submodule stdlib_sparse_spmv_coo
end submodule stdlib_sparse_spmv_coo
25 changes: 20 additions & 5 deletions src/sparse/stdlib_sparse_spmv_csc.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ contains
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op

call spmv_csc_sub_${rank}$d_${s1}$(matrix%data,matrix%colptr,matrix%row,matrix%nnz,matrix%nrows,matrix%ncols,matrix%storage, &
vec_x,vec_y,alpha,beta,op)

end subroutine

module subroutine spmv_csc_sub_${rank}$d_${s1}$(data,colptr,row,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: colptr(:) !! matrix column pointer
integer(ilp), intent(in) :: row(:) !! matrix row pointer
integer(ilp), intent(in) :: nnz !! number of non-zero values
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage !! storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
${t1}$ :: alpha_
character(1) :: op_
integer(ilp) :: i, j
Expand All @@ -38,8 +57,6 @@ contains
vec_y = zero_${s1}$
endif

associate( data => matrix%data, colptr => matrix%colptr, row => matrix%row, &
& nnz => matrix%nnz, nrows => matrix%nrows, ncols => matrix%ncols, storage => matrix%storage )
if( storage == sparse_full .and. op_==sparse_op_none ) then
do concurrent(j=1:ncols)
aux = alpha_ * vec_x(${rksfx2(rank-1)}$j)
Expand Down Expand Up @@ -110,10 +127,8 @@ contains
end do
#:endif
end if
end associate
end subroutine

#:endfor
#:endfor

end submodule stdlib_sparse_spmv_csc
end submodule stdlib_sparse_spmv_csc
27 changes: 21 additions & 6 deletions src/sparse/stdlib_sparse_spmv_csr.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ contains
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op

call spmv_csr_sub_${rank}$d_${s1}$(matrix%data, matrix%col, matrix%rowptr, matrix%nnz, matrix%nrows, matrix%ncols, matrix%storage, &
vec_x,vec_y,alpha,beta,op)

end subroutine

module subroutine spmv_csr_sub_${rank}$d_${s1}$(data,col,rowptr,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:)
integer(ilp), intent(in) :: col(:) !! matrix column pointer
integer(ilp), intent(in) :: rowptr(:) !! matrix row pointer
integer(ilp), intent(in) :: nnz !! number of non-zero values
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage !! storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
${t1}$ :: alpha_
character(1) :: op_
integer(ilp) :: i, j
Expand All @@ -37,9 +56,6 @@ contains
else
vec_y = zero_${s1}$
endif

associate( data => matrix%data, col => matrix%col, rowptr => matrix%rowptr, &
& nnz => matrix%nnz, nrows => matrix%nrows, ncols => matrix%ncols, storage => matrix%storage )

if( storage == sparse_full .and. op_==sparse_op_none ) then
do i = 1, nrows
Expand Down Expand Up @@ -114,10 +130,9 @@ contains
end do
#:endif
end if
end associate
end subroutine

#:endfor
#:endfor

end submodule stdlib_sparse_spmv_csr
end submodule stdlib_sparse_spmv_csr
26 changes: 21 additions & 5 deletions src/sparse/stdlib_sparse_spmv_ell.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ contains
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op

call spmv_ell_sub_${rank}$d_${s1}$(matrix%data,matrix%index,matrix%K, &
matrix%nnz,matrix%nrows,matrix%ncols,matrix%storage, &
vec_x,vec_y,alpha,beta,op)
end subroutine

module subroutine spmv_ell_sub_${rank}$d_${s1}$(data,index,mnz_p_row,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
${t1}$, intent(in) :: data(:,:)
integer(ilp), intent(in) :: index(:,:)
integer, intent(in) :: mnz_p_row
integer(ilp), intent(in) :: nnz
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage
${t1}$, intent(in) :: vec_x${ranksuffix(rank)}$
${t1}$, intent(inout) :: vec_y${ranksuffix(rank)}$
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
${t1}$ :: alpha_
character(1) :: op_
integer(ilp) :: i, j, k
Expand All @@ -32,8 +51,6 @@ contains
else
vec_y = zero_${s1}$
endif
associate( data => matrix%data, index => matrix%index, MNZ_P_ROW => matrix%K, &
& nnz => matrix%nnz, nrows => matrix%nrows, ncols => matrix%ncols, storage => matrix%storage )
if( storage == sparse_full .and. op_==sparse_op_none ) then
do i = 1, nrows
do k = 1, MNZ_P_ROW
Expand Down Expand Up @@ -78,10 +95,9 @@ contains
end do
#:endif
end if
end associate
end subroutine

#:endfor
#:endfor

end submodule stdlib_sparse_spmv_ell
end submodule stdlib_sparse_spmv_ell
29 changes: 23 additions & 6 deletions src/sparse/stdlib_sparse_spmv_sellc.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ contains
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op

call spmv_sellc_sub_${s1}$(matrix%data, matrix%rowptr, matrix%col, matrix%chunk_size, &
matrix%nnz, matrix%nrows, matrix%ncols, matrix%storage, &
vec_x,vec_y,alpha,beta,op)

end subroutine

module subroutine spmv_sellc_sub_${s1}$(data,ia,ja,cs,nnz,nrows,ncols,storage,vec_x,vec_y,alpha,beta,op)
!! This algorithm was gracefully provided by Ivan Privec and adapted by Jose Alves
${t1}$, intent(in) :: data(:,:)
integer(ilp), intent(in) :: ia(:)
integer(ilp), intent(in) :: ja(:,:)
integer, intent(in) :: cs
integer(ilp), intent(in) :: nnz
integer(ilp), intent(in) :: nrows
integer(ilp), intent(in) :: ncols
integer, intent(in) :: storage
${t1}$, intent(in) :: vec_x(:)
${t1}$, intent(inout) :: vec_y(:)
${t1}$, intent(in), optional :: alpha
${t1}$, intent(in), optional :: beta
character(1), intent(in), optional :: op
${t1}$ :: alpha_
character(1) :: op_
integer(ilp) :: i, nz, rowidx, num_chunks, rm
Expand All @@ -29,9 +51,6 @@ contains
vec_y = zero_${s1}$
endif

associate( data => matrix%data, ia => matrix%rowptr , ja => matrix%col, cs => matrix%chunk_size, &
& nnz => matrix%nnz, nrows => matrix%nrows, ncols => matrix%ncols, storage => matrix%storage )

if( .not.any( ${CHUNKS}$ == cs ) ) then
print *, "error: sellc chunk size not supported."
return
Expand Down Expand Up @@ -107,7 +126,6 @@ contains
print *, "error: sellc format for spmv operation not yet supported."
return
end if
end associate

contains
#:for chunk in CHUNKS
Expand Down Expand Up @@ -187,7 +205,6 @@ contains
#:endif

end subroutine

#:endfor

end submodule stdlib_sparse_spmv_sellc
end submodule stdlib_sparse_spmv_sellc
Loading
Loading