Multiply matrix with a part of a vector

Hello. I want to multiply a banded matrix d_a (width=height=Ns) with a part of a vector d_x (size=Ns*Ns).
Suppose I want to multiply d_a with a part of d_x starting from the 10th element of it. The following code doesn’t work.



where kl=ku=2, al=1, bet=0.

There are two explanations: 1)Either it is wrong or, 2) Multiplying a Matrix with a part of a vector doesn’t work

Which of the two is happening?

If you have a matrix of size Ns*Ns, and you want to multiply it by a vector of length Ns, even if that vector is a contiguous subset of another vector, you should be able to do that.

I’m puzzled as to why you would pass d_x instead of d_x+10, if you want to start with the 10th element of d_x.

  1. When you say “The following code doesn’t work.” What do you mean exactly?
  • you get an error in stat?
  • numerically the results in d_y are wrong?
  • something else?
  1. is d_x actually a vector of length Ns*Ns? Or is it really a two-dimensional data set and you are trying to use a row or column of it?

  2. What happens if you do:


Sorry. The code was



d_x is a vector of NsNs length. d_y has been initialized as zero vector of NsNs length. The result of the multiplication of the code Ihad written was a zero vector.

It should work assuming Ns>10. Note that the result of a matrix Ns*Ns multiplied by a vector of length Ns is a vector of length Ns. So there is no reason as you have written it that d_y needs to be a vector longer than length Ns, and the result of the multiplication would be stored in the first Ns locations in y, as you have written it. You would probably need to provide a short, complete example. Also run your test case with cuda-memcheck and see if any errors are reported.