Skip to content

Instantly share code, notes, and snippets.

@kelindar
Created March 18, 2015 17:49
Show Gist options
  • Save kelindar/bb78f6480b84dd3b5c52 to your computer and use it in GitHub Desktop.
Save kelindar/bb78f6480b84dd3b5c52 to your computer and use it in GitHub Desktop.
Data Locality: Matmul
void A(int n, int** a, int** b, int** c){
parallel_for(0, n, [&](int k)
{
for (int i = 0; i<n; i++) {
int r = a[i][k];
for (int j = 0; j<n; j++)
c[i][j] += r * b[k][j];
}
});
};
void Parallel_KJI(int n, int** a, int** b, int** c){
parallel_for(0, n, [&](int k)
{
for (int j = 0; j<n; j++) {
int r = b[k][j];
for (int i = 0; i<n; i++)
c[i][j] += a[i][k] * r;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment