File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " mandelbrot.hpp"
2
+
3
+ #ifdef NO_COMPLEX
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 double cr = col * STEP + MIN_X;
16
+ const double ci = row * STEP + MIN_Y;
17
+
18
+
19
+ // z = z^2 + c
20
+ double zr = 0 ;
21
+ double zi = 0 ;
22
+
23
+ for (uint16_t k = 1 ; k <= ITERATIONS; ++k) {
24
+ double zr2 = zr*zr;
25
+ double zi2 = zi*zi;
26
+ double zrzi = zr * zi;
27
+
28
+ zr = (zr2 - zi2) + cr;
29
+ zi = (zrzi + zrzi) + ci;
30
+ zr2 = zr*zr;
31
+ zi2 = zi*zi;
32
+ double mag2 = zr2 + zi2;
33
+ if (mag2 >= 4.0 ) {
34
+ image[pos] = k;
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
You can’t perform that action at this time.
0 commit comments