Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Fastest method to sum matrix

Tan__Elad
Einsteiger
2.232Aufrufe
Hello,

I want to take the sum of a product of two symmetric matrices, meaning that if A and B are symmetric matrices than I want to compute
c=sum(A*B)
where c is a scalar and the multiplication is done element wise. Is there some way to do this by using an MKL routine or is the fastest method using the default compiler commands?

Elad
0 Kudos
1 Lösung
mecej4
Geehrter Beitragender III
2.232Aufrufe
It seems to me that you really do not want a matrix product, but the scalar product of two vectors (i.e., 1-D arrays) that happen to be mis-arranged as square matrices. Look up the reshape function in your Fortran manual, so that you can cast the operation that is desired by you into an equivalent scalar product evaluation.

Lösung in ursprünglichem Beitrag anzeigen

4 Antworten
mecej4
Geehrter Beitragender III
2.233Aufrufe
It seems to me that you really do not want a matrix product, but the scalar product of two vectors (i.e., 1-D arrays) that happen to be mis-arranged as square matrices. Look up the reshape function in your Fortran manual, so that you can cast the operation that is desired by you into an equivalent scalar product evaluation.
Tan__Elad
Einsteiger
2.232Aufrufe
That seems like a good idea, do you think it will be worth my time to work with 1D arrays (which will make the code very unreadable) or just do a reshape every time (this product will occur a lot of times using matrices which are typically (1024,1024) big, so basically I'm asking if the reshape command is very time consuming)

Elad
Tan__Elad
Einsteiger
2.232Aufrufe
Is there some routine other than reshape that converts a symmetrical matrix into a packed scheme?
mecej4
Geehrter Beitragender III
2.232Aufrufe
Fortran has always allowed argument association between multidimensional arrays and one-dimensional arrays, as in the example below. Note that this will not work if you use subroutine arguments of assumed shape.

[fortran]program treshape
integer A(3,3)
data  A/11,12,13,21,22,23,31,32,33/
call sub(A,3*3)
end program treshape

subroutine sub(A,n)
integer A(n)
write(*,10)(i,A(i),i=1,n)
10 format(I4,2x,I4)
return
end subroutine sub
[/fortran]
Converting a dense matrix to packed or banded matrices is straightforward. Read the section on matrix storage schemes in the MKL manual.
Antworten