Skip to content

CSR space matrix vector product with stdlib #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tof92130 opened this issue Mar 31, 2025 · 3 comments
Closed

CSR space matrix vector product with stdlib #972

tof92130 opened this issue Mar 31, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@tof92130
Copy link

Description

Hello,

1/ With gnu compilers, I am using subroutine spmv from stdlib in order to realize a CSR sparse matrix vector product :

call spmv(matrix=mat%STDL, vec_x=x0, vec_y=x1, alpha=alpha, beta=beta) !> x1 = alpha mat%STDL x0 + beta x0

2/ With Intel compilers, I am using mkl_dcsrmv subroutine for same operation.

3/ I also have a my own procedure for this operation.

If beta=0 we should find x1 = mat%STDL x0

it I the case with mkl_dcsrmv and my own procedure but to obtain this result with procedure spmv from sodlib I must initialize x1(:) to 0d0 before (not good for bandwidth).

Here is my own procedure:

          do iRow=1,size(mat%STDL%rowptr)-1
            x1(iRow)=beta*x1(iRow)
            !$OMP SIMD
            do jMat=mat%STDL%rowptr(iRow),mat%STDL%rowptr(iRow+1)-1
              x1(iRow)=x1(iRow)+alpha*mat%STDL%data(jMat)*x0(mat%STDL%col(jMat))
            enddo
          enddo

line 2 initialise x1 to zero if beta=0.

Expected Behaviour

initialize x1 to zero when beta=0

Version of stdlib

60d0a76

Platform and Architecture

Mac/OS ARM and Intel

Additional Information

No response

@tof92130 tof92130 added the bug Something isn't working label Mar 31, 2025
@jalvesz
Copy link
Contributor

jalvesz commented Mar 31, 2025

Hi @tof92130, thanks for signaling this. I'm intrigued though:

At the beginning of the procedure one can find

if(present(beta)) then
vec_y = beta * vec_y
else
vec_y = zero_${s1}$
endif

Which should clean y following:
y = alpha*op(matrix)*x + beta * y
y should indeed be zero if beta == 0. Could you show us the results you are obtaining?

@tof92130
Copy link
Author

Indeed, it should work...

I investigate my program to see if the problem couldn't come from elsewhere (?)

@tof92130
Copy link
Author

can you please close this issue.

I solved the problem by initialising x1(:) and x2(:) just after first initialisation. Size of x1(:) and x2(:) are larger than size(mat%STDL%rowptr)-1 because I also include place for MPI exchange and I probably introduced bad values because of that.

intel compilers initialize to zero after allocation, gnu compilers do not.

@jalvesz jalvesz closed this as completed Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants