Application optimization and modeling

Which optimization strategies would you suggest for the piece of code below? Write down what you expect to give the best performance. You may test your work by performing benchmark runs. You can find a working code in the examples subfolder OPT.


double mat[N][N], s[N][N], val;
int i, j, v[N];
//
// ... v[] and s[][] may be assumed to contain valid data
//
for(i=0; i<N ; ++i) {
for(j=0; j<N; ++j) {
val = (double)(v[i] % 256);
mat[j][i] = s[j][i]*(sin(val)*sin(val)-cos(val)*cos(val));
}
}


No assumptions about the size of N may be made. You may however assume that the code is part of a function that gets called very frequently. s[][] and v[] may change between calls, and all entries of v[] are positive.

Further thoughts:

  • Does the optimization strategy depend on the problem size?
  • Can you predict an upper performance limit on one socket? Can you achieve this limit with your code? (This will only be possible after you have learned about the Roofline model)
Last modified: Tuesday, 28 March 2017, 9:11 AM