Hi all,
I have a simple task at hand. I want to compute an element-by-element multiplication of two matrices A and B.
If use C = A*B it delivers the result I want, but it is very slow.
Do you know any faster way to make this computation?
For instance, if A and B were vectors, vdmul would be an efficient way to proceed. I'm looking for something similar, but using matrices.
Thanks!
Gaston
Link Copied
Dear customer,
For the element-by-element multiplication, I am afraid there's no specify function for matrix, but only vector. If you would like to improve the performance, you could try with multi-threading calculation by using
#pragma omp parallel for for (int i = 0; i < row; i++) { vdMul(col, a, b, y); }
More physical core you have for your CPU, the higher performance you will get. Please also provide the testing performance with your hardware information to us, we will see if the performance acceptable. Thank you.
Best regards,
Fiona
Sergey Kostrov wrote:
>>...I have a simple task at hand. I want to compute an element-by-element multiplication of two matrices A and B.
If your matrices are stored as vectors, that is as 1-D data sets, like double dMxA[ size ], dMxB[ size ], etc,, then vdMul needs to be used.
1-D representation of a matrix is very efficient ( contiguous memory blocks ).
In this case you can even do hadamard with BLAS functions tbmv or sbmv. Both allow the input matrix to be stored in banded matrix form. With number of super-diagonals = 0 you only need to supply the diagonal, which in this case is one of the vectors
For more complete information about compiler optimizations, see our Optimization Notice.