-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
48 lines (35 loc) · 1.17 KB
/
helpers.c
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
41
42
43
44
45
46
47
48
doubleTYPE** createDoubleSquareMatrix(int dimension, double value){
doubleTYPE** matrix = malloc(dimension * sizeof(doubleTYPE*));
for(int i=0; i<dimension; i++){
matrix[i] = malloc(dimension * sizeof(doubleTYPE));
}
#pragma omp parallel for
for(int i=0; i<dimension; i++){
for(int j=0; j<dimension; j++){
matrix[i][j] = value;
}
}
return matrix;
}
floatTYPE** createFloatSquareMatrix(int dimension, float value){
floatTYPE** matrix = malloc(dimension * sizeof(floatTYPE*));
for(int i=0; i<dimension; i++){
matrix[i] = malloc(dimension * sizeof(floatTYPE));
}
#pragma omp parallel for
for(int i=0; i<dimension; i++){
for(int j=0; j<dimension; j++){
matrix[i][j] = value;
}
}
return matrix;
}
double getElapsedTime(struct timeval t1, struct timeval t0){
return (t1.tv_sec-t0.tv_sec) * 1.0f + (t1.tv_usec - t0.tv_usec) / 1000000.0f;
}
double getMFlops(int iterations, double elapsedTime){
double Flops = iterations/elapsedTime;
// Calculate Mega Flops Formula: F lops * 10raised to (-6).
double mFlops = (double)Flops/1000000;
return mFlops;
}