Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
about dgemm in lapack

Subject: about dgemm in lapack

From: kumar vishwajeet

Date: 22 Dec, 2010 07:25:05

Message: 1 of 5

I am using lapack and blas libraries in my C code. I have to multiply A(3 x 3) and B(3 x 1000) to get C(3 x 1000). Could anyone tell me what should be the leading dimension of A , B and C?? Since I am working in C the index starts at 0 rather than at 1 in MATLAB. Please also tell me how do you decide the leading dimension while working in C??

Thanks

Subject: about dgemm in lapack

From: Jan Simon

Date: 22 Dec, 2010 09:35:05

Message: 2 of 5

Dear Kumar,

> I am using lapack and blas libraries in my C code. I have to multiply A(3 x 3) and B(3 x 1000) to get C(3 x 1000). Could anyone tell me what should be the leading dimension of A , B and C??

Beside the method of reading the BLAS documentation, you could easily try to insert some 3s, 2s, 1000s, 999s in the call and check the results. I know aksing the newsgroup is more sophisticated, but I'm an experimental physicist.

Good luck, Jan

PS. Don't forget to save all open files in Matlab at first! The wrong numbers might cause a funny crash.

Subject: about dgemm in lapack

From: James Tursa

Date: 23 Dec, 2010 17:00:22

Message: 3 of 5

"kumar vishwajeet" wrote in message <ies94g$621$1@fred.mathworks.com>...
> I am using lapack and blas libraries in my C code. I have to multiply A(3 x 3) and B(3 x 1000) to get C(3 x 1000). Could anyone tell me what should be the leading dimension of A , B and C?? Since I am working in C the index starts at 0 rather than at 1 in MATLAB. Please also tell me how do you decide the leading dimension while working in C??

For the dimensions in the BLAS libraries, think MATLAB (or Fortran) dimensions, not C dimensions. The memory layout expected by the BLAS routines is the same as MATLAB and Fortran. So the leading dimensions of A, B, and C are all 3. Remember, though, that you are passing everything by reference, not by value. So *don't* just put a 3 in the argument list of the call. You will need to create a variable to hold the 3 value and then pass the address of that to dgemm. e.g., here is the interface

http://www.netlib.org/blas/dgemm.f

      SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
* .. Scalar Arguments ..
      DOUBLE PRECISION ALPHA,BETA
      INTEGER K,LDA,LDB,LDC,M,N
      CHARACTER TRANSA,TRANSB
* ..
* .. Array Arguments ..
      DOUBLE PRECISION A(LDA,*),B(LDB,*),C(LDC,*)

And according to the MATLAB doc you should be using mwSignedIndex for the integer types being passed. So that means you should be using the following:

char TRANSA, TRANSB;
mwSignedIndex M, N, K, LDA, LDB, LDC;
double ALPHA, BETA;
double *A, *B, *C;

TRANSA = 'N';
TRANAB = 'N';
M = 3;
N = 1000;
K = 3;
LDA = 3;
LDB = 3;
LDC = 3;
ALPHA = 1.0;
BETA = 1.0;
A = whatever; // your 1st input
B = whatever; // your 2nd input
C = whatever; // your pre-allocated output
dgemm( &TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);


James Tursa

Subject: about dgemm in lapack

From: James Tursa

Date: 23 Dec, 2010 18:20:22

Message: 4 of 5

"James Tursa" wrote in message <ievv76$43k$1@fred.mathworks.com>...

> BETA = 1.0;

Correction. For a first call where you are not adding to C you would do this:

BETA = 0.0;

> dgemm( &TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);

Also, on Unix systems you may need to call dgemm_ (i.e., with an underscore at the end).


James Tursa

Subject: about dgemm in lapack

From: James Tursa

Date: 23 Dec, 2010 18:34:05

Message: 5 of 5

"James Tursa" wrote in message <ievv76$43k$1@fred.mathworks.com>...

> TRANAB = 'N';

Typo. Should be:

 TRANSB = 'N';


James Tursa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us