Exercise: General code optimization

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. A sequential example code can be found in the directory 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.
Can you develop a performance model for your optimized code? What is the code balance for large N? Can you match the model with a serial/OpenMP-parallel code?
Last modified: Thursday, 9 April 2015, 10:06 PM