1748246 Members
3079 Online
108760 Solutions
New Discussion юеВ

__restrict keyword

 
SOLVED
Go to solution
tiyyagura sunil reddy
Occasional Contributor

__restrict keyword

Hello,

I was trying to use __restrict key word with pointers used as fuction parameters. I have the impression that this keyword only operates on "Single pointes". I dont see any performance improvement when I use the keyword with double pointers. Should __restrict keyword only be used with single pointers??
I would be grateful if someone can answer to my query.

Thanks in advance
sunil
6 REPLIES 6
Elmar P. Kolkman
Honored Contributor

Re: __restrict keyword

I think it will depends on how you try to use the double pointer... and on how the compiler can speed up the code thanks to the restrict keyword.

I think you should try to write it down to a single pointer function to have it speed up right now.
Every problem has at least one solution. Only some solutions are harder to find.
Mike Stroyan
Honored Contributor

Re: __restrict keyword

The __restrict keyword can be very helpful to the HP-UX C and C++ compilers on itanium systems. Here is an example using restrict with pointers to doubles. It produces 70% better performance with the __restrict keyword.
tiyyagura sunil reddy
Occasional Contributor

Re: __restrict keyword

I would first like to thank Elmar and Mike for responding to my question. Though your replies were informative I would like to make my question more clearer. I wanted to ask whether the __restrict keyword would affect a double pointer (int **p). I tried this for myself, but could not see any performance improvement when the keywork is used with a double pointer.
example:

void accum_restrict(int **__restrict a, int **b, m,n)
{
int i,j;
for(i=0;ifor(j=0;ja[i][j] = (b[i][j]*100)/12;
}

I dont see any improvement in performance for the above code with restrict keyword. Does this mean that the restrict keyword only operates on a single pointer (int *p).

Thanks once again.

sunil
Mike Stroyan
Honored Contributor
Solution

Re: __restrict keyword

I do see a benefit from using __restrict if you apply it to both of the "int **" parameters. For maximum effect you could actually write "int * __restrict * _restrict a", assuming that neither the pointer arrays or the int arrays overlap.
Elmar P. Kolkman
Honored Contributor

Re: __restrict keyword

Or try it this way:

inline void accum2_restrict(int *__restrict a2,int *b2, n) {
int j;
for (j=0;ja2[j]=(b[j]*100)/12;
}

void accum_restrict(int **__restrict a, int **b, m,n)
{
int i;
for(i=0;iaccum2_restrict(a[i],b[i],n);
}

Haven't tried it, but that should do the trick. It might not accept the inline, replace it by static then, making it a local function which can be optimized better.
Every problem has at least one solution. Only some solutions are harder to find.
tiyyagura sunil reddy
Occasional Contributor

Re: __restrict keyword

Thanks Elmar and Mike. That solved my problem.

sunil