Hi guys, I'm having trouble understanding how this routine works.

cblas_dgemm is a BLAS function that gives C <= alpha*AB + beta*C

where A,B,C are matrices and alpha, beta are scalars.

It takes 14 parameters, listed http://www.psatellite.com/matrixlib/api/lapack.html" [Broken].

http://en.wikipedia.org/wiki/General_Matrix_Multiply" [Broken] on wikipedia.

I don't understand what the "major stride" (lda,ldb,ldc) is or how it works, despite the explanations given on both sites.

Here are my example matrices:

[itex]A = \begin{bmatrix}1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1

\end{bmatrix}

[/itex]

[itex]

B = \begin{bmatrix}1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1

\end{bmatrix}

[/itex]

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0

\end{bmatrix}

[/itex]

I want to be able to take the bottom quarter submatrices of A and B, multiply them and add them to C such that

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &2 &2 \\ 0

&0 &2 &2

\end{bmatrix}

[/itex]

Here's an excerpt from my code:

This code successfully multiplies A by B and gets C, a matrix filled with 4's.

I'm thinking something like:

but that returns

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 2

&2 &2 &2 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0

\end{bmatrix}

[/itex]

instead.

I think it's because I don't understand the lda, ldb and ldc parameters. Is it possible to get what I want here, through only using cblas_dgemm? Obviously, I could iterate over the arrays with loops but I'd prefer not to have to do that.

cblas_dgemm is a BLAS function that gives C <= alpha*AB + beta*C

where A,B,C are matrices and alpha, beta are scalars.

Code:

```
void cblas_xgemm (
const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB,
const int M,
const int N,
const int K,
const SCALAR alpha,
const TYPE * A,
const int lda,
const TYPE * B,
const int ldb,
const SCALAR beta,
TYPE * C,
const int ldc)
```

http://en.wikipedia.org/wiki/General_Matrix_Multiply" [Broken] on wikipedia.

I don't understand what the "major stride" (lda,ldb,ldc) is or how it works, despite the explanations given on both sites.

Here are my example matrices:

[itex]A = \begin{bmatrix}1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1

\end{bmatrix}

[/itex]

[itex]

B = \begin{bmatrix}1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1 \\ 1

&1 &1 &1

\end{bmatrix}

[/itex]

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0

\end{bmatrix}

[/itex]

I want to be able to take the bottom quarter submatrices of A and B, multiply them and add them to C such that

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 0

&0 &0 &0 \\ 0

&0 &2 &2 \\ 0

&0 &2 &2

\end{bmatrix}

[/itex]

Here's an excerpt from my code:

Code:

```
//where n is the matrix size, in this case 4
void Multiply(int n, int blockSize, double** a, double** b, double** c)
{
cblas_dgemm(CblasRowMajor,CblasNoTrans, CblasNoTrans, n, n , n , 1.0, a[0], n, b[0], n, 1.0, c[0], n);
}
```

I'm thinking something like:

Code:

```
//where n is the matrix size, in this case 4
void Multiply(int n, int blockSize, double** a, double** b, double** c)
{
cblas_dgemm(CblasRowMajor,CblasNoTrans, CblasNoTrans, 2, 2 , 2 , 1.0, a[1], n, b[1], n, 1.0, c[1], n);
}
```

[itex]

C = \begin{bmatrix}0

&0 &0 &0 \\ 2

&2 &2 &2 \\ 0

&0 &0 &0 \\ 0

&0 &0 &0

\end{bmatrix}

[/itex]

instead.

I think it's because I don't understand the lda, ldb and ldc parameters. Is it possible to get what I want here, through only using cblas_dgemm? Obviously, I could iterate over the arrays with loops but I'd prefer not to have to do that.

Last edited by a moderator: