-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-3-optimization-flags.c
54 lines (47 loc) · 1.38 KB
/
2-3-optimization-flags.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
49
50
51
52
53
54
// clang 2-optimization-flags.c -o 2-optimization-flags.out -fopenmp -O0
// clang 2-optimization-flags.c -o 2-optimization-flags.out -fopenmp -O1
// clang 2-optimization-flags.c -o 2-optimization-flags.out -fopenmp -O2
// clang 2-optimization-flags.c -o 2-optimization-flags.out -fopenmp -O3
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <omp.h>
int N = 32768, x, y, n_threads;
float a = 2, b = 3, **A, **B;
double t_init;
void initialization()
{
t_init = omp_get_wtime();
A = (float **)malloc(N * sizeof(float *));
B = (float **)malloc(N * sizeof(float *));
for (x = 0; x < N; x++)
{
A[x] = (float *)malloc(N * sizeof(float));
B[x] = (float *)malloc(N * sizeof(float));
for (y = 0; y < N; y++)
{
A[x][y] = 1.0f;
B[x][y] = 0.0f;
}
}
// printf("Initialization: %0.15f\n", omp_get_wtime() - t_init);
}
int main()
{
n_threads = omp_get_max_threads();
omp_set_max_active_levels(1);
omp_set_num_threads(n_threads);
omp_set_dynamic(0);
initialization();
t_init = omp_get_wtime();
for (x = 1; x < N - 1; x++)
{
for (y = 1; y < N - 1; y++)
{
B[x][y] = a * A[x][y] + b * (A[x - 1][y] + A[x + 1][y] + A[x][y - 1] + A[x][y + 1]);
}
}
printf("Optimization Flags: %0.15f\n", omp_get_wtime() - t_init);
free(A);
free(B);
}