Skip to content

Instantly share code, notes, and snippets.

@pubudu91
Created November 10, 2016 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pubudu91/005da4c778b1b003285e65a559b5dbeb to your computer and use it in GitHub Desktop.
Save pubudu91/005da4c778b1b003285e65a559b5dbeb to your computer and use it in GitHub Desktop.
void parallelMultiply1D(Matrix1D *A, Matrix1D *B, Matrix1D *C, int n) {
omp_set_num_threads(4);
#pragma omp parallel for
for (int i = 0; i < n; ++i) {
double *Arow = &A->matrix[i * n];
double *Crow = &C->matrix[i * n];
for (int j = 0; j < n; ++j) {
double sum = 0;
for (int k = 0; k < n; ++k)
sum += *(Arow + k) * B->matrix[k * n + j];
*(Crow + j) = sum;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment