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

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

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

--Gennady

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

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

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

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

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

thank for your reply.

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

is there a function to sum a vector?

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

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

please refer to the MKLdocumentationfor more details.

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

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.

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

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