-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenMP.h
More file actions
40 lines (31 loc) · 812 Bytes
/
openMP.h
File metadata and controls
40 lines (31 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef OPENMP_H_
#define OPENMP_H_
#include <omp.h>
#include <stdlib.h>
#include "matrix.h"
int openMP(matrix* A, matrix* B, matrix* result, int number_of_threads)
{
if (!matchDimensions(A, B, result)) return 0;
omp_set_num_threads(number_of_threads);
#pragma omp parallel
{
// int num = omp_get_num_threads();
// printf("%d Threads\n", num);
for (int i = 0; i<A->rows; ++i)
{
#pragma omp for
for (int j = 0; j<B->columns; ++j)
{
double element = 0;
for (int k = 0; k<A->columns; ++k)
{
element += A->values[i * A->columns + k] * B->values[k
* B->columns + j];
}
result->values[i * result->columns + j] = element;
}
}
}
return 1;
}
#endif