Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- CBLAS level 3 routine problem

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

stanleyimko

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-19-2011
11:33 PM

87 Views

CBLAS level 3 routine problem

int main()

{

const int n = 3, m = 2;

double A

double d[n*m], e[n*m];

/*************************

two dimension storage:

A = 1, 2 B = 1, 1

2, 3 1, 1

3, 4 1, 1

*************************/

for( int i = 0; i < n; i++ )

for( int j = 0; j < m; j++ ){

A

B

}

/*************************

one dimension storage

with column-major:

d = {1, 2, 3, 2, 3, 4}

e = {1, 1, 1, 1, 1, 1}

*************************/

for( int j = 0; j < m; j++ )

for( int i = 0; i < n; i++ ){

d[j*n+i] = A

e[j*n+i] = B

}

/*********************************

Call dgemm:

C := alpha*op(A)*op(B) + beta*C

********************************/

/************CBLAS***************/

CBLAS_ORDER order;

order = CblasRowMajor; //specify row major

CBLAS_TRANSPOSE transa;

transa = CblasTrans; // transpose A

CBLAS_TRANSPOSE transb;

transb = CblasNoTrans;

int lda = n; //the first dimension of A

int ldb = n; //the first dimension of B

int ldc = m; //the first dimension of C

double alpha = 1.0, beta = 0.0;

double C

cblas_dgemm( order, transa, transb, m, m, n,

alpha, *A, lda, *B, ldb, beta, *C, ldc);

for( int i = 0; i < m; i++ ){

for( int j = 0; j < m; j++ ){

cout << C

}

cout << endl;

}

/*********direct Fotran call*********/

double f[m*m];

char transaa = 'T';

char transbb = 'N';

dgemm( &transaa, &transbb, &m, &m, &n,

α, d, &lda, e, &ldb, β, f, &ldc);

cout << endl;

for( int i = 0; i < m*m; i++ )

cout << f

cout << endl;

return 0;

}

5, 6,

6, 7,

6, 9, 6, 9,

1 Solution

Murat_G_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-20-2011
09:45 PM

87 Views

The leading dimensions for the CBLAS call are set incorrectly. For the row-major matrix format, the leading dimensions should stride rows of the matrix. Since your 2D arrays are A

[cpp] CBLAS_ORDER order; order = CblasRowMajor; //specify row major CBLAS_TRANSPOSE transa; transa = CblasTrans; // transpose A CBLAS_TRANSPOSE transb; transb = CblasNoTrans; int lda = m; //modified leading dimension for A int ldb = m; //modified leading dimension for B int ldc = m; //the first dimension of C [/cpp]

Then, before the FORTRAN dgemm call, we need to reset

[cpp] /*********direct Fotran call*********/ lda = n; //reset the leading dimension of A ldb = n; //reset the leading dimension of B double f[m*m]; char transaa = 'T'; char transbb = 'N'; dgemm( &transaa, &transbb, &m, &m, &n, α, d, &lda, e, &ldb, β, f, &ldc);[/cpp]

After these modifications, I get same results from CBLAS and FORTRAN dgemm:

6, 6,

9, 9,

6, 9, 6, 9,

Best wishes,

Efe

Link Copied

2 Replies

Murat_G_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-20-2011
09:45 PM

88 Views

The leading dimensions for the CBLAS call are set incorrectly. For the row-major matrix format, the leading dimensions should stride rows of the matrix. Since your 2D arrays are A

[cpp] CBLAS_ORDER order; order = CblasRowMajor; //specify row major CBLAS_TRANSPOSE transa; transa = CblasTrans; // transpose A CBLAS_TRANSPOSE transb; transb = CblasNoTrans; int lda = m; //modified leading dimension for A int ldb = m; //modified leading dimension for B int ldc = m; //the first dimension of C [/cpp]

Then, before the FORTRAN dgemm call, we need to reset

[cpp] /*********direct Fotran call*********/ lda = n; //reset the leading dimension of A ldb = n; //reset the leading dimension of B double f[m*m]; char transaa = 'T'; char transbb = 'N'; dgemm( &transaa, &transbb, &m, &m, &n, α, d, &lda, e, &ldb, β, f, &ldc);[/cpp]

After these modifications, I get same results from CBLAS and FORTRAN dgemm:

6, 6,

9, 9,

6, 9, 6, 9,

Best wishes,

Efe

stanleyimko

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-21-2011
04:53 AM

87 Views

Thanks so much. I am kind of misunderstanding the dimension stuff. I should check carefully before posting the thread next time.

Regards,

Stanley

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.