File tree Expand file tree Collapse file tree 8 files changed +225
-8
lines changed Expand file tree Collapse file tree 8 files changed +225
-8
lines changed Original file line number Diff line number Diff line change 1
1
#include " mandelbrot.hpp"
2
2
3
- #ifdef BASELINE
3
+ #ifdef BASELINE_DP
4
4
int64_t mandelbrot_computation (ofstream &matrix_out) {
5
5
uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
6
6
@@ -18,10 +18,10 @@ int64_t mandelbrot_computation(ofstream &matrix_out) {
18
18
{
19
19
z = pow (z, 2 ) + c;
20
20
21
+ image[pos] = i;
21
22
// If it is convergent
22
23
if (abs (z) >= 2 )
23
24
{
24
- image[pos] = i;
25
25
break ;
26
26
}
27
27
}
Original file line number Diff line number Diff line change
1
+ #include " mandelbrot.hpp"
2
+
3
+ #ifdef BASELINE_SP
4
+ int64_t mandelbrot_computation (ofstream &matrix_out) {
5
+ uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
6
+
7
+ const auto start = chrono::steady_clock::now ();
8
+ for (int pos = 0 ; pos < HEIGHT * WIDTH; ++pos)
9
+ {
10
+
11
+ const int row = pos / WIDTH;
12
+ const int col = pos % WIDTH;
13
+ const complex<float > c (col * STEP + MIN_X, row * STEP + MIN_Y);
14
+
15
+ // z = z^2 + c
16
+ complex<float > z (0 , 0 );
17
+ for (int i = 1 ; i <= ITERATIONS; ++i)
18
+ {
19
+ z = pow (z, 2 ) + c;
20
+
21
+ image[pos] = i;
22
+ // If it is convergent
23
+ if (abs (z) >= 2 )
24
+ {
25
+ break ;
26
+ }
27
+ }
28
+ }
29
+ const auto end = chrono::steady_clock::now ();
30
+ auto difference =chrono::duration_cast<chrono::milliseconds>(end - start).count ();
31
+ cerr << " Time elapsed: "
32
+ << difference
33
+ << " milliseconds." << endl;
34
+ for (int row = 0 ; row < HEIGHT; row++)
35
+ {
36
+ for (int col = 0 ; col < WIDTH; col++)
37
+ {
38
+ matrix_out << image[row * WIDTH + col];
39
+
40
+ if (col < WIDTH - 1 )
41
+ matrix_out << ' ,' ;
42
+ }
43
+ if (row < HEIGHT - 1 )
44
+ matrix_out << endl;
45
+ }
46
+ matrix_out.close ();
47
+
48
+ delete[] image; // It's here for coding style, but useless
49
+ return difference;
50
+ }
51
+ #endif
Original file line number Diff line number Diff line change 1
1
#include " mandelbrot.hpp"
2
2
3
- #ifdef DYNAMIC_MULTITHREADING
3
+ #ifdef DYNAMIC_MULTITHREADING_DP
4
4
int64_t mandelbrot_computation (ofstream &matrix_out)
5
5
{
6
6
uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
@@ -21,9 +21,9 @@ int64_t mandelbrot_computation(ofstream &matrix_out)
21
21
z = pow (z, 2 ) + c;
22
22
23
23
// If it is convergent
24
+ image[pos] = i;
24
25
if (abs (z) >= 2 )
25
26
{
26
- image[pos] = i;
27
27
break ;
28
28
}
29
29
}
Original file line number Diff line number Diff line change
1
+ #include " mandelbrot.hpp"
2
+
3
+ #ifdef DYNAMIC_MULTITHREADING_SP
4
+ int64_t mandelbrot_computation (ofstream &matrix_out)
5
+ {
6
+ uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
7
+
8
+ const auto start = chrono::steady_clock::now ();
9
+ #pragma omp parallel for schedule(dynamic, 1)
10
+ for (int pos = 0 ; pos < HEIGHT * WIDTH; ++pos)
11
+ {
12
+
13
+ const int row = pos / WIDTH;
14
+ const int col = pos % WIDTH;
15
+ const complex<float > c (col * STEP + MIN_X, row * STEP + MIN_Y);
16
+
17
+ // z = z^2 + c
18
+ complex<float > z (0 , 0 );
19
+ for (int i = 1 ; i <= ITERATIONS; ++i)
20
+ {
21
+ z = pow (z, 2 ) + c;
22
+
23
+ // If it is convergent
24
+ image[pos] = i;
25
+ if (abs (z) >= 2 )
26
+ {
27
+ break ;
28
+ }
29
+ }
30
+ }
31
+ const auto end = chrono::steady_clock::now ();
32
+ auto difference = chrono::duration_cast<chrono::milliseconds>(end - start).count ();
33
+ cerr << " Time elapsed: "
34
+ << difference
35
+ << " milliseconds." << endl;
36
+ for (int row = 0 ; row < HEIGHT; row++)
37
+ {
38
+ for (int col = 0 ; col < WIDTH; col++)
39
+ {
40
+ matrix_out << image[row * WIDTH + col];
41
+
42
+ if (col < WIDTH - 1 )
43
+ matrix_out << ' ,' ;
44
+ }
45
+ if (row < HEIGHT - 1 )
46
+ matrix_out << endl;
47
+ }
48
+ matrix_out.close ();
49
+
50
+ delete[] image; // It's here for coding style, but useless
51
+ return difference;
52
+ }
53
+ #endif
Original file line number Diff line number Diff line change 1
1
#include " mandelbrot.hpp"
2
2
3
- #ifdef NO_COMPLEX
3
+ #ifdef NO_COMPLEX_DP
4
4
int64_t mandelbrot_computation (ofstream &matrix_out)
5
5
{
6
6
uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
@@ -30,8 +30,8 @@ int64_t mandelbrot_computation(ofstream &matrix_out)
30
30
zr2 = zr*zr;
31
31
zi2 = zi*zi;
32
32
double mag2 = zr2 + zi2;
33
+ image[pos] = k;
33
34
if (mag2 >= 4.0 ) {
34
- image[pos] = k;
35
35
break ;
36
36
}
37
37
}
Original file line number Diff line number Diff line change
1
+ #include " mandelbrot.hpp"
2
+
3
+ #ifdef NO_COMPLEX_SP
4
+ int64_t mandelbrot_computation (ofstream &matrix_out)
5
+ {
6
+ uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
7
+
8
+ const auto start = chrono::steady_clock::now ();
9
+ #pragma omp parallel for schedule(dynamic, 1)
10
+ for (int pos = 0 ; pos < HEIGHT * WIDTH; ++pos)
11
+ {
12
+
13
+ const int row = pos / WIDTH;
14
+ const int col = pos % WIDTH;
15
+ const float cr = col * STEP + MIN_X;
16
+ const float ci = row * STEP + MIN_Y;
17
+
18
+
19
+ // z = z^2 + c
20
+ float zr = 0 ;
21
+ float zi = 0 ;
22
+
23
+ for (uint16_t k = 1 ; k <= ITERATIONS; ++k) {
24
+ float zr2 = zr*zr;
25
+ float zi2 = zi*zi;
26
+ float zrzi = zr * zi;
27
+
28
+ zr = (zr2 - zi2) + cr;
29
+ zi = (zrzi + zrzi) + ci;
30
+ zr2 = zr*zr;
31
+ zi2 = zi*zi;
32
+ float mag2 = zr2 + zi2;
33
+ image[pos] = k;
34
+ if (mag2 >= 4.0 ) {
35
+ break ;
36
+ }
37
+ }
38
+ }
39
+ const auto end = chrono::steady_clock::now ();
40
+ auto difference = chrono::duration_cast<chrono::milliseconds>(end - start).count ();
41
+ cerr << " Time elapsed: "
42
+ << difference
43
+ << " milliseconds." << endl;
44
+ for (int row = 0 ; row < HEIGHT; row++)
45
+ {
46
+ for (int col = 0 ; col < WIDTH; col++)
47
+ {
48
+ matrix_out << image[row * WIDTH + col];
49
+
50
+ if (col < WIDTH - 1 )
51
+ matrix_out << ' ,' ;
52
+ }
53
+ if (row < HEIGHT - 1 )
54
+ matrix_out << endl;
55
+ }
56
+ matrix_out.close ();
57
+
58
+ delete[] image; // It's here for coding style, but useless
59
+ return difference;
60
+ }
61
+ #endif
Original file line number Diff line number Diff line change 1
1
#include " mandelbrot.hpp"
2
2
3
- #ifdef STATIC_MULTITHREADING
3
+ #ifdef STATIC_MULTITHREADING_DP
4
4
int64_t mandelbrot_computation (ofstream &matrix_out) {
5
5
uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
6
6
@@ -19,10 +19,10 @@ int64_t mandelbrot_computation(ofstream &matrix_out) {
19
19
{
20
20
z = pow (z, 2 ) + c;
21
21
22
+ image[pos] = i;
22
23
// If it is convergent
23
24
if (abs (z) >= 2 )
24
25
{
25
- image[pos] = i;
26
26
break ;
27
27
}
28
28
}
Original file line number Diff line number Diff line change
1
+ #include " mandelbrot.hpp"
2
+
3
+ #ifdef STATIC_MULTITHREADING_SP
4
+ int64_t mandelbrot_computation (ofstream &matrix_out) {
5
+ uint16_t *const image = new uint16_t [HEIGHT * WIDTH];
6
+
7
+ const auto start = chrono::steady_clock::now ();
8
+ #pragma omp parallel for
9
+ for (int pos = 0 ; pos < HEIGHT * WIDTH; ++pos)
10
+ {
11
+
12
+ const int row = pos / WIDTH;
13
+ const int col = pos % WIDTH;
14
+ const complex<float > c (col * STEP + MIN_X, row * STEP + MIN_Y);
15
+
16
+ // z = z^2 + c
17
+ complex<float > z (0 , 0 );
18
+ for (int i = 1 ; i <= ITERATIONS; ++i)
19
+ {
20
+ z = pow (z, 2 ) + c;
21
+
22
+ image[pos] = i;
23
+ // If it is convergent
24
+ if (abs (z) >= 2 )
25
+ {
26
+ break ;
27
+ }
28
+ }
29
+ }
30
+ const auto end = chrono::steady_clock::now ();
31
+ auto difference =chrono::duration_cast<chrono::milliseconds>(end - start).count ();
32
+ cerr << " Time elapsed: "
33
+ << difference
34
+ << " milliseconds." << endl;
35
+ for (int row = 0 ; row < HEIGHT; row++)
36
+ {
37
+ for (int col = 0 ; col < WIDTH; col++)
38
+ {
39
+ matrix_out << image[row * WIDTH + col];
40
+
41
+ if (col < WIDTH - 1 )
42
+ matrix_out << ' ,' ;
43
+ }
44
+ if (row < HEIGHT - 1 )
45
+ matrix_out << endl;
46
+ }
47
+ matrix_out.close ();
48
+
49
+ delete[] image; // It's here for coding style, but useless
50
+ return difference;
51
+ }
52
+ #endif
You can’t perform that action at this time.
0 commit comments