aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-04-21 01:10:40 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-04-21 01:10:40 -0400
commit81dc61d0d7b17de6944ceb55ae3c7a3f3176731d (patch)
treeb2b253021ac60bc64c070ba2214f6055ae9e6a6a
parentc3415b624e5f80615a58002e37c5edc19721101e (diff)
implemented shared versions
-rw-r--r--TODO.md9
-rw-r--r--src/serial-fractals.c2
-rw-r--r--src/shared-fractals.c61
3 files changed, 67 insertions, 5 deletions
diff --git a/TODO.md b/TODO.md
index bf39605..7a5beca 100644
--- a/TODO.md
+++ b/TODO.md
@@ -3,13 +3,14 @@
## Program
* [ ] find way to render data into image files
+ * [x] read/write grids to/from file
* [ ] write serial
- * [ ] mandelbrot
- * [ ] multibrot
+ * [x] mandelbrot
+ * [x] multibrot
* [ ] julia
* [ ] write shared
- * [ ] mandelbrot
- * [ ] multibrot
+ * [x] mandelbrot
+ * [x] multibrot
* [ ] julia
* [ ] write gpu
* [ ] mandelbrot
diff --git a/src/serial-fractals.c b/src/serial-fractals.c
index bd4bc02..718fccb 100644
--- a/src/serial-fractals.c
+++ b/src/serial-fractals.c
@@ -1,6 +1,6 @@
-#include <complex.h>
#include "fractals.h"
#include "grids.h"
+
/*
* 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 mandelbrot set
diff --git a/src/shared-fractals.c b/src/shared-fractals.c
index f0d837e..9f65e80 100644
--- a/src/shared-fractals.c
+++ b/src/shared-fractals.c
@@ -1 +1,62 @@
#include "fractals.h"
+
+#include <omp.h>
+#include "fractals.h"
+
+/*
+ * 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 mandelbrot set
+ * This should be identical to the version found in serial-fractals.c
+ */
+size_t mandelbrot(const long double complex z0, const size_t max_iterations){
+ long double complex z = z0;
+ size_t iteration = 0;
+ while(cabsl(z) <= 2 && iteration < max_iterations){
+ z = z*z + z0;
+ iteration++;
+ }
+
+ return iteration;
+}
+
+/*
+ * Fills a grid with mandelbrot values
+ */
+void mandelbrot_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] = mandelbrot(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
+ * This should be identical to the version found in serial-fractals.c
+ */
+size_t multibrot(const long double complex z0, const size_t max_iterations, const double d){
+ long double complex z = z0;
+ size_t iteration = 0;
+ while(cabsl(z) <= 2 && iteration < max_iterations){
+ z = cpowl(z, d) + z0;
+ iteration++;
+ }
+ return iteration;
+}
+
+
+/*
+ * Fills a grid with multibrot values
+ */
+void multibrot_grid(grid_t* grid, const size_t max_iterations, const double d){
+ const size_t size = grid->size;
+ size_t* data = grid->data;
+
+ #pragma omp parallel for default(none) shared(data, size, grid, max_iterations, d) schedule(dynamic)
+ for(size_t i = 0; i < size; i ++){
+ data[i] = multibrot(grid_to_complex(grid, i), max_iterations, d);
+ }
+}