-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single and double precision for everything.
- Loading branch information
Showing
8 changed files
with
225 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "mandelbrot.hpp" | ||
|
||
#ifdef BASELINE_SP | ||
int64_t mandelbrot_computation(ofstream &matrix_out) { | ||
uint16_t *const image = new uint16_t[HEIGHT * WIDTH]; | ||
|
||
const auto start = chrono::steady_clock::now(); | ||
for (int pos = 0; pos < HEIGHT * WIDTH; ++pos) | ||
{ | ||
|
||
const int row = pos / WIDTH; | ||
const int col = pos % WIDTH; | ||
const complex<float> c(col * STEP + MIN_X, row * STEP + MIN_Y); | ||
|
||
// z = z^2 + c | ||
complex<float> z(0, 0); | ||
for (int i = 1; i <= ITERATIONS; ++i) | ||
{ | ||
z = pow(z, 2) + c; | ||
|
||
image[pos] = i; | ||
// If it is convergent | ||
if (abs(z) >= 2) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
const auto end = chrono::steady_clock::now(); | ||
auto difference =chrono::duration_cast<chrono::milliseconds>(end - start).count(); | ||
cerr << "Time elapsed: " | ||
<< difference | ||
<< " milliseconds." << endl; | ||
for (int row = 0; row < HEIGHT; row++) | ||
{ | ||
for (int col = 0; col < WIDTH; col++) | ||
{ | ||
matrix_out << image[row * WIDTH + col]; | ||
|
||
if (col < WIDTH - 1) | ||
matrix_out << ','; | ||
} | ||
if (row < HEIGHT - 1) | ||
matrix_out << endl; | ||
} | ||
matrix_out.close(); | ||
|
||
delete[] image; // It's here for coding style, but useless | ||
return difference; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "mandelbrot.hpp" | ||
|
||
#ifdef DYNAMIC_MULTITHREADING_SP | ||
int64_t mandelbrot_computation(ofstream &matrix_out) | ||
{ | ||
uint16_t *const image = new uint16_t[HEIGHT * WIDTH]; | ||
|
||
const auto start = chrono::steady_clock::now(); | ||
#pragma omp parallel for schedule(dynamic, 1) | ||
for (int pos = 0; pos < HEIGHT * WIDTH; ++pos) | ||
{ | ||
|
||
const int row = pos / WIDTH; | ||
const int col = pos % WIDTH; | ||
const complex<float> c(col * STEP + MIN_X, row * STEP + MIN_Y); | ||
|
||
// z = z^2 + c | ||
complex<float> z(0, 0); | ||
for (int i = 1; i <= ITERATIONS; ++i) | ||
{ | ||
z = pow(z, 2) + c; | ||
|
||
// If it is convergent | ||
image[pos] = i; | ||
if (abs(z) >= 2) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
const auto end = chrono::steady_clock::now(); | ||
auto difference = chrono::duration_cast<chrono::milliseconds>(end - start).count(); | ||
cerr << "Time elapsed: " | ||
<< difference | ||
<< " milliseconds." << endl; | ||
for (int row = 0; row < HEIGHT; row++) | ||
{ | ||
for (int col = 0; col < WIDTH; col++) | ||
{ | ||
matrix_out << image[row * WIDTH + col]; | ||
|
||
if (col < WIDTH - 1) | ||
matrix_out << ','; | ||
} | ||
if (row < HEIGHT - 1) | ||
matrix_out << endl; | ||
} | ||
matrix_out.close(); | ||
|
||
delete[] image; // It's here for coding style, but useless | ||
return difference; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "mandelbrot.hpp" | ||
|
||
#ifdef NO_COMPLEX_SP | ||
int64_t mandelbrot_computation(ofstream &matrix_out) | ||
{ | ||
uint16_t *const image = new uint16_t[HEIGHT * WIDTH]; | ||
|
||
const auto start = chrono::steady_clock::now(); | ||
#pragma omp parallel for schedule(dynamic, 1) | ||
for (int pos = 0; pos < HEIGHT * WIDTH; ++pos) | ||
{ | ||
|
||
const int row = pos / WIDTH; | ||
const int col = pos % WIDTH; | ||
const float cr = col * STEP + MIN_X; | ||
const float ci = row * STEP + MIN_Y; | ||
|
||
|
||
// z = z^2 + c | ||
float zr = 0; | ||
float zi = 0; | ||
|
||
for (uint16_t k = 1; k <= ITERATIONS; ++k) { | ||
float zr2 = zr*zr; | ||
float zi2 = zi*zi; | ||
float zrzi = zr * zi; | ||
|
||
zr = (zr2 - zi2) + cr; | ||
zi = (zrzi + zrzi) + ci; | ||
zr2 = zr*zr; | ||
zi2 = zi*zi; | ||
float mag2 = zr2 + zi2; | ||
image[pos] = k; | ||
if(mag2 >= 4.0) { | ||
break; | ||
} | ||
} | ||
} | ||
const auto end = chrono::steady_clock::now(); | ||
auto difference = chrono::duration_cast<chrono::milliseconds>(end - start).count(); | ||
cerr << "Time elapsed: " | ||
<< difference | ||
<< " milliseconds." << endl; | ||
for (int row = 0; row < HEIGHT; row++) | ||
{ | ||
for (int col = 0; col < WIDTH; col++) | ||
{ | ||
matrix_out << image[row * WIDTH + col]; | ||
|
||
if (col < WIDTH - 1) | ||
matrix_out << ','; | ||
} | ||
if (row < HEIGHT - 1) | ||
matrix_out << endl; | ||
} | ||
matrix_out.close(); | ||
|
||
delete[] image; // It's here for coding style, but useless | ||
return difference; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "mandelbrot.hpp" | ||
|
||
#ifdef STATIC_MULTITHREADING_SP | ||
int64_t mandelbrot_computation(ofstream &matrix_out) { | ||
uint16_t *const image = new uint16_t[HEIGHT * WIDTH]; | ||
|
||
const auto start = chrono::steady_clock::now(); | ||
#pragma omp parallel for | ||
for (int pos = 0; pos < HEIGHT * WIDTH; ++pos) | ||
{ | ||
|
||
const int row = pos / WIDTH; | ||
const int col = pos % WIDTH; | ||
const complex<float> c(col * STEP + MIN_X, row * STEP + MIN_Y); | ||
|
||
// z = z^2 + c | ||
complex<float> z(0, 0); | ||
for (int i = 1; i <= ITERATIONS; ++i) | ||
{ | ||
z = pow(z, 2) + c; | ||
|
||
image[pos] = i; | ||
// If it is convergent | ||
if (abs(z) >= 2) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
const auto end = chrono::steady_clock::now(); | ||
auto difference =chrono::duration_cast<chrono::milliseconds>(end - start).count(); | ||
cerr << "Time elapsed: " | ||
<< difference | ||
<< " milliseconds." << endl; | ||
for (int row = 0; row < HEIGHT; row++) | ||
{ | ||
for (int col = 0; col < WIDTH; col++) | ||
{ | ||
matrix_out << image[row * WIDTH + col]; | ||
|
||
if (col < WIDTH - 1) | ||
matrix_out << ','; | ||
} | ||
if (row < HEIGHT - 1) | ||
matrix_out << endl; | ||
} | ||
matrix_out.close(); | ||
|
||
delete[] image; // It's here for coding style, but useless | ||
return difference; | ||
} | ||
#endif |