Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use intel prefetch pragma when data hidden inside an object?

Intel helpfully provides a prefetch pragma; for example

#pragma prefetch a
for(i=0; i<m; i++)
  a[i]=b[i]+1;

will prefetch a a certain number of loop cycles ahead, as determined by the compiler.

But what if a is not an array but a class with [] overridden? If operator[] does a simple array access, can prefetch still be used in this way?

(Presumably the question applies to std::vectors as well).

like image 868
Sideshow Bob Avatar asked Sep 14 '11 11:09

Sideshow Bob


1 Answers

One way to find out is to try it and look at the assembly. And if anything else, just benchmark it with and without the pragma. However, I'm not sure if the prefetch pragma is what you want:

The prefetch pragma is supported by Intel® Itanium® processors only.

http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011/compiler_c/cref_cls/common/cppref_pragma_prefetch_noprefetch.htm

Are you really writing this for an Itanium?

On x86/x64 systems, simple loops like that with sequential memory access are already well handled by the hardware prefetcher. So it may not help at all to do manual prefetching.

See here for a prefetching example: Prefetching Examples?

like image 51
Mysticial Avatar answered Oct 20 '22 01:10

Mysticial