|
"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
|