Page 1 of 1
Cannot find routine for: matrix-vector-product

Posted:
Sun Sep 09, 2007 5:16 pm
by Mat
Hello,
i'm to blind to find the Lapack routine for a matrix-vector multiplication.
what i need is to solve the following:
r = Av - w
where A is a matrix, v and w are vectors.
It would be very nice if anybode could help me....thanks a lot.
Re: Cannot find routine for: matrix-vector-product

Posted:
Sun Sep 09, 2007 6:51 pm
by buttari
Mat wrote:Hello,
i'm to blind to find the Lapack routine for a matrix-vector multiplication.
what i need is to solve the following:
r = Av - w
where A is a matrix, v and w are vectors.
It would be very nice if anybode could help me....thanks a lot.
Mat,
there's no matrix multiplication routine in LAPACK. Matrix multiplication is in BLAS and it is called _GEMM where "_" can be D, S, C, Z depending on the precision/data format you are using.
Alfredo

Posted:
Sun Sep 09, 2007 8:11 pm
by Julien Langou
Yep, and the matrix-vector product is _GEMV
First copy r in w with _COPY and then the _GEMV routine will do:
- Code: Select all
r <- Av - r
if you set ALPHA = 1.0 and BETA = 0.0.

Posted:
Mon Sep 10, 2007 12:54 am
by buttari
Julien Langou wrote:Yep, and the matrix-vector product is _GEMV
First copy r in w with _COPY and then the _GEMV routine will do:
- Code: Select all
r <- Av - r
if you set ALPHA = 1.0 and BETA = 0.0.
yep, thanks Julien.
Alfredo

Posted:
Tue Sep 11, 2007 6:21 am
by Mat
Thanks a lot.
Julien, for my task i want to solve: r = Av - w; so i think i have to copy w into r and set BETA to 1.0. The solution is with the routine DGEMV than in r.
Could anybode explain the DGEMV argument INCY to me?
What is that:
* INCY - INTEGER.
* On entry, INCY specifies the increment for the elements of
* Y. INCY must not be zero.
* Unchanged on exit.
What value should INCY have?
And what is INCX?
Perhaps both 1 ?

Posted:
Tue Sep 11, 2007 6:43 am
by sven
Dear Mat,
You want to copy w into r and set ALPHA = 1.0D0, BETA = -1.0D0. DGEMV computes
r <= alpha*A*v + beta*r
The increment allows you to stride through a vector. For example, with INCY = 2, the routine accesses every second element of Y, that is Y(1), Y(3), Y(5), ..., Y(2*N-1).
It is mainly used to allow a row of a matrix to be passed to the routine. If the leading dimension of X is LDX, then passing Y as X(2,1) and INCY as LDX,
would take Y as the second row of X.
Sven Hammarling.

Posted:
Tue Sep 11, 2007 6:55 am
by Mat
Thank you very much Sven,
so for a simple matrix-vector operation a need both with "1".
Thanks

Posted:
Tue Sep 11, 2007 7:06 am
by sven
Yes, both increments equal to 1,
Sven.

Posted:
Wed Sep 12, 2007 10:22 am
by Mat
Hello,
it's me again:
Now i'm searching a routine for a vector-vector multiplication.
for this: r^T * v
where r is a transposed vector and v is a vector.
Or should i use _GEMV with A as a vector?
Thanks a lot.

Posted:
Wed Sep 12, 2007 10:39 am
by sven
Hello Mat,
Look at the Level 1 BLAS. DAXPY does
y <- alpha*x + y
and DDOT
alpha = x^T*y
Sven.

Posted:
Wed Sep 12, 2007 10:55 am
by Mat
Thanks a lot sven,
does the Level1-Blas routine exits for COMPLEX values as well? I cannot find something like zdot ?
I would like to be able to do x^T*y for Complex vectors...
Thanks for your patience.

Posted:
Wed Sep 12, 2007 11:06 am
by sven
Hi Mat,
Yes, ZDOTU for x^T*y and ZDOTC for x^H*y. The netlib page for the BLAS is at:
http://www.netlib.org/blas/index.html
The BLAS also come with LAPACK, together with documentation in the form of man pages and html files.
Of course, for efficiency it is preferable to use vendor supplied BLAS, or the Atlas BLAS.
Sven.

Posted:
Wed Sep 12, 2007 11:47 am
by Mat
THanks,
do i need something special? Perhaps i need to install BLAS of level 1?
Like the _gemv routine i have the following in my c++ code:
- Code: Select all
extern "C" {
void zgemv_(char* TRANS,
int* M,
int* N,
COMPLEX* ALPHA,
COMPLEX A[],
int* LDA,
COMPLEX X[],
int* INCX,
COMPLEX* BETA,
COMPLEX Y[],
int* INCY);
double DDOT( int N,
double DX[],
int INCX,
double DY[],
int INCY);
};
But using it the way i use for example zgemv_ i get an undefined reference to DDOT ?
EDIT: I got the point: I have to use the small letters like in dgemv with an underscore at the end: ddot_