aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/fractals.c5
-rw-r--r--src/fractals.h7
-rw-r--r--src/precision.h2
-rw-r--r--src/serial-fractals.c30
-rw-r--r--src/shared-fractals.c32
5 files changed, 73 insertions, 3 deletions
diff --git a/src/fractals.c b/src/fractals.c
index 82e4ef6..269bfaf 100644
--- a/src/fractals.c
+++ b/src/fractals.c
@@ -126,7 +126,7 @@ int main(const int argc, char *argv[]) {
// const CBASE complex constant = -0.835L -0.321L* I;
const double radius = 100;
- enum fractal f = MULTICORN;
+ enum fractal f = BURNING_SHIP;
switch(f){
case MANDELBROT:
mandelbrot_grid(grid, iterations);
@@ -140,6 +140,9 @@ int main(const int argc, char *argv[]) {
case MULTICORN:
multicorn_grid(grid, iterations, degree);
break;
+ case BURNING_SHIP:
+ burning_ship_grid(grid, iterations);
+ break;
case JULIA:
julia_grid(grid, iterations, constant, radius);
break;
diff --git a/src/fractals.h b/src/fractals.h
index 3f2757d..2b296eb 100644
--- a/src/fractals.h
+++ b/src/fractals.h
@@ -10,8 +10,8 @@ enum fractal {
MANDELBROT, // IMPLEMENTED IN SERIAL SHARED
TRICORN, // IMPLEMENTED IN SERIAL SHARED
MULTIBROT, // IMPLEMENTED IN SERIAL SHARED
- MULTICORN, // IMPLEMENTED in SERIAL SHARED
- BURNING_SHIP, // NOT IMPLEMENTED IN ANY VERSION
+ MULTICORN, // IMPLEMENTED IN SERIAL SHARED
+ BURNING_SHIP, // IMPLEMENTED IN SERIAL SHARED
//NEWTON, // MIGHT NEVER BE IMPLEMENTED, REQUIRES SPECIAL COLORING
JULIA // IMPLEMENTED IN SERIAL SHARED
};
@@ -22,6 +22,9 @@ void mandelbrot_grid(grid_t* grid, const size_t max_iterations);
size_t tricorn(const CBASE complex z0, const size_t max_iterations);
void tricorn_grid(grid_t* grid, const size_t max_iterations);
+size_t burning_ship(const CBASE complex z0, const size_t max_iterations);
+void burning_ship_grid(grid_t* grid, const size_t max_iterations);
+
size_t multibrot(const CBASE complex z0, const size_t max_iterations, const double d);
void multibrot_grid(grid_t* grid, const size_t max_iterations, const double d);
diff --git a/src/precision.h b/src/precision.h
index e83122a..4bca354 100644
--- a/src/precision.h
+++ b/src/precision.h
@@ -13,6 +13,7 @@
#define CPOW cpowl
#define CONJ conjl
#define CABS cabsl
+#define RABS fabsl
#define CFORMAT "%Lf"
#endif
@@ -24,6 +25,7 @@
#define CPOW cpow
#define CONJ conj
#define CABS cabs
+#define RABS fabs
#define CFORMAT "%lf"
#endif
diff --git a/src/serial-fractals.c b/src/serial-fractals.c
index 2647d11..4e081c3 100644
--- a/src/serial-fractals.c
+++ b/src/serial-fractals.c
@@ -1,4 +1,5 @@
#include "fractals.h"
+#include <math.h>
#include "precision.h"
#include "grids.h"
@@ -59,6 +60,35 @@ void tricorn_grid(grid_t* grid, const size_t max_iterations){
/*
* Computes the number of iterations it takes for a point z0 to become unbounded
+ * if the return value is equal to max_iterations, the point lies within the burningship set (oh no! I hope they have fire safety gear)
+ */
+size_t burning_ship(const CBASE complex z0, const size_t max_iterations) {
+ CBASE complex z = z0;
+ CBASE complex z_mod;
+ size_t iteration = 0;
+
+ while (CABS(z) <= 2 && iteration < max_iterations) {
+ z_mod = RABS(CREAL(z)) + RABS(CIMAG(z))*I;
+ z = z_mod * z_mod + z0;
+ iteration++;
+ }
+ return iteration;
+}
+
+/*
+ * Fills a grid with burning_ship values
+ */
+void burning_ship_grid(grid_t* grid, const size_t max_iterations){
+ const size_t size = grid->size;
+ size_t* data = grid->data;
+
+ for(size_t i = 0; i < size; i++){
+ data[i] = burning_ship(grid_to_complex(grid, i), max_iterations);
+ }
+}
+
+/*
+ * Computes the number of iterations it takes for a point z0 to become unbounded
* if the return value is equal to max_iterations, the point lies within the multibrot set
* This is implementation closely matches mandelbrot, but uses cpow which might degrade performance.
*/
diff --git a/src/shared-fractals.c b/src/shared-fractals.c
index 3390e14..92c8c9a 100644
--- a/src/shared-fractals.c
+++ b/src/shared-fractals.c
@@ -1,6 +1,7 @@
#include "fractals.h"
#include <omp.h>
+#include <math.h>
#include "fractals.h"
#include "precision.h"
@@ -60,6 +61,37 @@ void tricorn_grid(grid_t* grid, const size_t max_iterations){
data[i] = tricorn(grid_to_complex(grid, i), max_iterations);
}
}
+
+/*
+ * Computes the number of iterations it takes for a point z0 to become unbounded
+ * if the return value is equal to max_iterations, the point lies within the burningship set (oh no! I hope they have fire safety gear)
+ */
+size_t burning_ship(const CBASE complex z0, const size_t max_iterations) {
+ CBASE complex z = z0;
+ CBASE complex z_mod;
+ size_t iteration = 0;
+
+ while (CABS(z) <= 2 && iteration < max_iterations) {
+ z_mod = RABS(CREAL(z)) + RABS(CIMAG(z))*I;
+ z = z_mod * z_mod + z0;
+ iteration++;
+ }
+ return iteration;
+}
+
+/*
+ * Fills a grid with burning_ship values
+ */
+void burning_ship_grid(grid_t* grid, const size_t max_iterations){
+ const size_t size = grid->size;
+ size_t* data = grid->data;
+
+ #pragma omp parallel for default(none) shared(data, size, grid, max_iterations) schedule(dynamic)
+ for(size_t i = 0; i < size; i++){
+ data[i] = burning_ship(grid_to_complex(grid, i), max_iterations);
+ }
+}
+
/*
* Computes the number of iterations it takes for a point z0 to diverge
* if the return value is equal to max_iterations, the point lies within the multibrot set