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 Topics
- Intel® Moderncode for Parallel Architectures
- MKL Distance Between Vector

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

brachi

Beginner

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

01-31-2011
03:53 AM

179 Views

MKL Distance Between Vector

Does anybody know if the MKL contains a function tocalaulate the distance between 2 vectors.

sqrt((x1 - y1)(x1-y1) + (x2 - y2)(x2 - y2) ........(Xn - Yn)(Xn - Yn))

BB

Link Copied

8 Replies

Gennady_F_Intel

Moderator

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

01-31-2011
05:03 AM

179 Views

--Gennady

Gennady_F_Intel

Moderator

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

01-31-2011
05:16 AM

179 Views

i've forget to add, you can find the similarfunctionalityinto another performance library - IPP. see Signal Processingdomain: functions Sub (Subtracts the elements of two vectors) and then Sqrt (Computes a square root of each element of a vector.

--Gennady

TimP

Black Belt

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

02-01-2011
02:58 AM

179 Views

brachi

Beginner

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

02-01-2011
11:40 PM

179 Views

how do I use the intel compiler? hwat are the optimization options?

thank for your reply.

brachi

Beginner

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

02-02-2011
03:19 AM

179 Views

is there a function to sum a vector?

Gennady_F_Intel

Moderator

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

02-02-2011
03:28 AM

179 Views

yes. See the ?asum routines which compute the sum of magnitudes of the vector elements.

please refer to the MKLdocumentationfor more details.

timintel

Beginner

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

02-02-2011
04:21 AM

179 Views

Since you say you want speed, plain C or Fortran code, with a vectorizing compiler, would be a better bet.

If you are using the current Intel C or Fortran, and haven't figured out how to use the simd reduction directive, let us know which compiler you want sample code for. Do you know Fortran ?

sqrt(dot_product(x-y,x-y))

If that doesn't vectorize (requires /fp:fast), it's embarrassing, but you could then fall back on the directive.

If your cases are long enough for threading to be useful, and auto-parallel doesn't do the entire job, we could give you examples in openmp, or maybe someone on TBB or cilk or ArBB forum could help you, if you have chosen one of those C++ namespaces.

(untested; show us your code)

sum = 0

!dir$ omp parallel do reduction(+: sum) private (diff) if(n>9999)

!dir$ simd reduction(+: sum)

do i=1,n

diff = x(i) - y(i)

sum = sum + diff**2

end do

yourresult = sqrt(sum)

In fact, the Qparallel /Qpar-threshold0 appear to handle this better than the OpenMP and simd directives.

In my example, when alignment is asserted, the compiler chooses only vectorization, no threading, even at par-threshold0. As the SSE2 vector code produces 4 parallel sums, which are added implicitly at the end, implementing 8 loop iterations per pass, you can see that a big data set would be needed before threading could prove beneficial.

jimdempseyatthecove

Black Belt

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

02-02-2011
07:56 AM

179 Views

How large is n in:

sqrt((x1 - y1)(x1-y1) + (x2 - y2)(x2 - y2) ........(Xn - Yn)(Xn - Yn))

How frequently is the above set differenced? (integrated)

And how many different matched such vector differences are made?

The answers to these questions will alter the coding strategy.

Also is: sqrt((x1 - y1)(x1-y1) + (x2 - y2)(x2 - y2) ........(Xn - Yn)(Xn - Yn))

Used for an absolute distance or for use in ordering distances between vector pairings? (ordering by proximity). IOW can you eliminate the ^2 and sqrt by using sum of abs?

Jim Dempsey

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.