use of scheduler, generate 4k images

This commit is contained in:
Mylloon 2024-04-24 01:42:11 +02:00
parent d927f95d6a
commit 8f0aecb444
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -12,12 +12,12 @@
struct mandelbrot_args { struct mandelbrot_args {
unsigned int *image; unsigned int *image;
double scale; double scale;
int dx, dy, width, height; int x, y, dx, dy, width, height;
}; };
struct mandelbrot_args * struct mandelbrot_args *
new_mandelbrot_args(unsigned int *image, double scale, int dx, int dy, new_mandelbrot_args(unsigned int *image, double scale, int x, int y, int dx,
int width, int height) int dy, int width, int height)
{ {
struct mandelbrot_args *args; struct mandelbrot_args *args;
@ -28,6 +28,8 @@ new_mandelbrot_args(unsigned int *image, double scale, int dx, int dy,
args->image = image; args->image = image;
args->scale = scale; args->scale = scale;
args->x = x;
args->y = y;
args->dx = dx; args->dx = dx;
args->dy = dy; args->dy = dy;
args->width = width; args->width = width;
@ -86,7 +88,7 @@ torgb(int n)
} }
void void
draw(void *closure, struct scheduler *s) draw_pixel(void *closure, struct scheduler *s)
{ {
struct mandelbrot_args *args = (struct mandelbrot_args *)closure; struct mandelbrot_args *args = (struct mandelbrot_args *)closure;
unsigned int *image = args->image; unsigned int *image = args->image;
@ -94,15 +96,38 @@ draw(void *closure, struct scheduler *s)
int dx = args->dx; int dx = args->dx;
int dy = args->dy; int dy = args->dy;
int width = args->width; int width = args->width;
(void)s; // pas de nouvelle tâche dans le scheduler
free(closure);
unsigned rgb = torgb(mandel(toc(dx, dy, dx, dy, scale)));
image[dy * width + dx] = rgb;
}
void
draw(void *closure, struct scheduler *s)
{
struct mandelbrot_args *args = (struct mandelbrot_args *)closure;
unsigned int *image = args->image;
double scale = args->scale;
int x = args->x;
int y = args->y;
int dx = args->dx;
int dy = args->dy;
int width = args->width;
int height = args->height; int height = args->height;
free(closure); free(closure);
for(int y = 0; y < height; y++) { for(; y < height; y++) {
for(int x = 0; x < width; x++) { for(; x < width; x++) {
/* TODO: Utiliser s */ int rc = sched_spawn(
unsigned rgb = torgb(mandel(toc(x, y, dx, dy, scale))); draw_pixel,
image[y * width + x] = rgb; new_mandelbrot_args(image, scale, x, y, dx, dy, width, height),
s);
assert(rc >= 0);
} }
} }
} }
@ -126,8 +151,8 @@ benchmark_mandelbrot(int serial, int nthreads)
struct timespec begin, end; struct timespec begin, end;
double delay; double delay;
int rc; int rc;
int width = 1920; int width = 3840;
int height = 1080; int height = 2160;
double scale = width / 4.0; double scale = width / 4.0;
int dx = width / 2; int dx = width / 2;
int dy = height / 2; int dy = height / 2;
@ -144,7 +169,7 @@ benchmark_mandelbrot(int serial, int nthreads)
} else { } else {
rc = sched_init( rc = sched_init(
nthreads, width * height, draw, nthreads, width * height, draw,
new_mandelbrot_args(image, scale, dx, dy, width, height)); new_mandelbrot_args(image, scale, 0, 0, dx, dy, width, height));
assert(rc >= 0); assert(rc >= 0);
} }