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
- How to do an element-wise multiplication between two 3D-arrays?

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

Lin__JH

Beginner

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

07-26-2019
05:49 AM

69 Views

How to do an element-wise multiplication between two 3D-arrays?

Hi, everyone.

I am trying to do some element-wise multiplication between two 3D arrays/matrices and then calculate the sum of all the elements returned. Something like this:

res = 0 do k = kstart,kend do j = jstart, jend do i = istart, iend res = res + A(i, j, k) * B(i, j ,k) end do end do end do

However, such multiplication is not applied to all the elements in A or B but the elements that were involved between the iteration variables. To make the calculation faster, I tried the** ddot** function in **MKL** like this:

n = (kend - kstart + 1) * (jend - jstart + 1) * (iend - istart + 1) res = ddot(n, A(istart:iend, jstart:jend, kstart:kend), 1, B(istart:iend, jstart:jend, kstart:kend), 1)

But in this way I couldn't get the same result as I did by using three do-loops.

Anyone who might tell me where the problem is?

Thanks :)

Link Copied

2 Replies

mecej4

Black Belt

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

07-27-2019
05:12 PM

69 Views

Lin, JH wrote:

However, such multiplication is not applied to all the elements in A or B but the elements that were involved between the iteration variables.

Please explain what you mean by the sentence above. What iterations? What does "involved between" mean?

The codes that you showed above appear intended to multiply and sum ALL elements within the limits istart:iend, etc. Please reconcile these codes with what you wrote regarding applying the summation to a selected subset.

Hinds__David

Beginner

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

08-14-2019
09:44 PM

69 Views

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.