Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Finding elementwise and conditional matrix multiplication implementation with MKL

aketh_t_
Beginner
747 Views

Hi all,

I have been looking for an MKL version of elementwise matrix multiplication that works based on a condional approach.While Vmult can be used it is for only a 1D vector rather than a matrix.

Below is the code I would like to rewrite with MKL version if possible.

logical(log_kind) check(2000,2000)

do i=1,2000

   do j=1,2000

   if ( check(i,j) )

   c(i,j) = a(i,j) * b(i,j) 

   enddo

enddo 

I know Vmult helps, but it has no conditional operation.

Is there is a conditional Vector library or elementwise matrix library.

Can this be done by a combination of MKL library operations?

 

 

 

 

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
747 Views

If the check array has a large number of .TRUE., then consider replacing the logical check array with an array of values 0.0 for false and 1.0 for true. Then use

real :: use_this(2000,2000)
...
do j=1,2000 ! outer loop to be rightmost index
   do i=1,2000 ! inner loop to be the leftmost index
       c(i,j) = c(i,j) + a(i,j) * b(i,j) * use_this(i, j)
   enddo
enddo 

Jim Dempsey

0 Kudos
TimP
Honored Contributor III
747 Views

The original code, with corrected syntax (either f66 one-line if or inserting endif) should work well, at least since SSE4, possibly with the addition of a directive such as !dir$ vector always in order to relax the constraint about exceptions.  At -O3, ifort should fix the backward loop nesting automatically.

The (different) case which Jim quotes can be handled efficiently by e.g.

c(i,j) = c(i,j) + a(i,j) * merge(b(i,j), 0., check(i,j))

(again, SSE4 or later would help)

0 Kudos
Reply