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
- Using MKL to Multiply Non-consecutive columns by a mtrix

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

Saleh__Ahmed

Beginner

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

03-13-2019
10:11 AM

77 Views

Using MKL to Multiply Non-consecutive columns by a mtrix

Hi

I am trying to use MKL to do some matrix multiplications. However I need to multiply specific columns in one matrix to another matrix. The problem is that cblac_dgemm takes successive columns, so how can I do this and only multiply certain columns knowing the starting pointer of each of course ?? I tried using a for loop to multiply each column by the matrix but the execution time is much larger than taking successive columns all at once I also don't want to copy the columns to a new variable to but them in a successive order because this also takes long time.

I tried using pthreads to do it in a more paralleled way however still no much improvement.

How does MKL handle parallelization and make it much better than OpenMP and pthreads?

Thanks in advance

Ahmed

Link Copied

3 Replies

Pamela_H_Intel

Moderator

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

03-13-2019
04:01 PM

77 Views

Ahmed,

I don't know if you want to do dot product or element-wise multiplication. And I don't know whether you want to use C or FORTRAN. But you can start with the following.

- If you want to use MKL to multiply one column by another column, that would be vector-vector multiplication, just pass in the starting point of the column - see Vector Math Library for element-wise and BLAS for dot
- If you want to use MKL to multiply one column by a matrix, that would be vector matrix multiplication.

cblas_?dot for the vector-vector dot procuct in C - where the '?' is s, d, c, or z for single, double, complex single, or complex double

v?Mul for vector-vector element-wise multiplication, i.e.

**Fortran:**

call vsmul( n, a, b, y ), call vdmul( n, a, b, y ), call vcmul( n, a, b, y ), call vzmul( n, a, b, y )

**C:**

vsMul( n, a, b, y );, vdMul( n, a, b, y );, vcMul( n, a, b, y );, vzMul( n, a, b, y );

As for how MKL optimizes parallelization - we have teams of software developers who like to play with math. They try out different algorithms and use math tricks (like reorganizing the solution process) and try out their solutions on different chips and with different sized problems to determine which solutions fit which problem sets.

I hope this helps.

Pamela

Saleh__Ahmed

Beginner

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

03-14-2019
10:24 AM

77 Views

Thank you Pamela for your response I truly appreciate it.

Answering your questions, I use C++ and I am trying to do very fast matrix multiplication (not element-wise). I tried all the functions you mentioned my problem is that I want to multiply certain columns in the first matrix (not the whole matrix) to the second one. but using a for loop over the functions you mentioned is much slower than cblas_dgemm.

My question, Is there a way to use cblas_dgemm but for specific columns in the first matrix not the whole matrix because copying them to another position in the memory where they exist after each other is also time consuming.

Thank you very much

Ahmed

Kirill_V_Intel

Employee

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

03-15-2019
10:43 AM

77 Views

Hi Ahmed,

If I understand what you mean, you can try to use batch gemm, see

https://software.intel.com/en-us/mkl-developer-reference-fortran-gemm-batch

and

https://software.intel.com/en-us/mkl-developer-reference-fortran-gemm3m-batch

where the general concept is described here:

https://software.intel.com/en-us/articles/introducing-batch-gemm-operations

Hope, this helps!

Best,

Kirill

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