Fixed warning and inconsistencies

This commit is contained in:
Yashar Alan Zenker
2026-07-04 19:31:58 +02:00
parent f28aff6e72
commit 8352e8d61e
+9 -9
View File
@@ -1,6 +1,6 @@
#include "tricorn_V4.h" #include "tricorn_V4.h"
static void compute(void * args); static void* compute(void * args);
static unsigned converge(float c_real, float c_imag, unsigned n); static unsigned converge(float c_real, float c_imag, unsigned n);
static size_t get_thread_count(); static size_t get_thread_count();
typedef struct { typedef struct {
@@ -29,17 +29,16 @@ typedef struct {
*/ */
void tricorn_V4(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ void tricorn_V4(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
const ssize_t min_pixels_per_thread = 50; const ssize_t min_rows_per_thread = 10;
_Bool flipped = height < 0; _Bool flipped = height < 0;
height = flipped ? -height : height; size_t abs_height = flipped ? -height : height;
size_t thread_count = get_thread_count(); size_t thread_count = get_thread_count();
if(height >= min_pixels_per_thread) if(height >= min_rows_per_thread)
while((height/thread_count) < min_pixels_per_thread) thread_count--; while((height/thread_count) < min_rows_per_thread) thread_count--;
else thread_count = 1; else thread_count = 1;
printf("%lu \n",thread_count);
const size_t y_step = (height+thread_count-1)/thread_count; const size_t y_step = (height+thread_count-1)/thread_count;
const float start_r = crealf(start); const float start_r = crealf(start);
@@ -53,7 +52,7 @@ void tricorn_V4(float complex start, size_t width, ssize_t height, float res, un
args->start_r =start_r; args->start_r =start_r;
args->start_i =start_i-i*directional_res*y_step; args->start_i =start_i-i*directional_res*y_step;
args->start_row = i*y_step; args->start_row = i*y_step;
args->stop_row = height < (args->start_row+y_step) ? height: (args->start_row+y_step); args->stop_row = abs_height < (args->start_row+y_step) ? abs_height: (args->start_row+y_step);
args->width = width; args->width = width;
args-> flipped = flipped; args-> flipped = flipped;
args->color = color; args->color = color;
@@ -66,14 +65,14 @@ void tricorn_V4(float complex start, size_t width, ssize_t height, float res, un
args = NULL; args = NULL;
} }
} }
for(int i = 0; i < thread_count; i++){ for(size_t i = 0; i < thread_count; i++){
pthread_join(threads[i],NULL); pthread_join(threads[i],NULL);
} }
return; return;
} }
static void compute(void * vargs){ static void* compute(void * vargs){
compute_args *args = vargs; compute_args *args = vargs;
vargs = NULL; vargs = NULL;
@@ -170,6 +169,7 @@ static void compute(void * vargs){
} }
free(args); free(args);
args = NULL; args = NULL;
return NULL;
} }
// Iterative application of the equation given by the assignment // Iterative application of the equation given by the assignment