custom qlen as parameter

This commit is contained in:
Mylloon 2024-05-05 14:18:20 +02:00
parent 692a69a9c4
commit 8704b182c3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 23 additions and 12 deletions

View file

@ -3,4 +3,4 @@
/* Lance le benchmark avec mandelbrot (TP10)
*
* Renvoie le temps d'exécution */
double benchmark_mandelbrot(int, int);
double benchmark_mandelbrot(int, int, int);

View file

@ -3,4 +3,4 @@
/* Lance le benchmark avec quicksort (fournis)
*
* Renvoie le temps d'exécution */
double benchmark_quicksort(int, int);
double benchmark_quicksort(int, int, int);

View file

@ -11,13 +11,14 @@ main(int argc, char *argv[])
{
int serial = 0;
int nthreads = -1;
int qlen = -1;
int quicksort = 0;
int mandelbrot = 0;
double delay;
int opt;
while((opt = getopt(argc, argv, "qmst:")) != -1) {
while((opt = getopt(argc, argv, "qmst:n:")) != -1) {
if(opt < 0) {
goto usage;
}
@ -35,6 +36,9 @@ main(int argc, char *argv[])
case 't':
nthreads = atoi(optarg);
break;
case 'n':
qlen = atoi(optarg);
break;
default:
goto usage;
}
@ -44,9 +48,9 @@ main(int argc, char *argv[])
}
if(quicksort) {
delay = benchmark_quicksort(serial, nthreads);
delay = benchmark_quicksort(serial, nthreads, qlen);
} else if(mandelbrot) {
delay = benchmark_mandelbrot(serial, nthreads);
delay = benchmark_mandelbrot(serial, nthreads, qlen);
} else {
goto usage;
}

View file

@ -175,15 +175,19 @@ draw_serial(unsigned int *image)
}
double
benchmark_mandelbrot(int serial, int nthreads)
benchmark_mandelbrot(int serial, int nthreads, int qlen)
{
unsigned int *image;
struct timespec begin, end;
double delay;
int rc;
int size = WIDTH * HEIGHT;
int n = WIDTH * HEIGHT;
if(!(image = malloc(WIDTH * HEIGHT * sizeof(unsigned int)))) {
if(qlen <= 0) {
qlen = n;
}
if(!(image = malloc(n * sizeof(unsigned int)))) {
perror("Image allocation");
return 1;
}
@ -193,7 +197,7 @@ benchmark_mandelbrot(int serial, int nthreads)
if(serial) {
draw_serial(image);
} else {
rc = sched_init(nthreads, size, draw,
rc = sched_init(nthreads, qlen, draw,
new_mandelbrot_args(image, 0, 0, WIDTH, HEIGHT));
assert(rc >= 0);
}

View file

@ -105,7 +105,7 @@ quicksort(void *closure, struct scheduler *s)
}
double
benchmark_quicksort(int serial, int nthreads)
benchmark_quicksort(int serial, int nthreads, int qlen)
{
int *a;
struct timespec begin, end;
@ -113,6 +113,10 @@ benchmark_quicksort(int serial, int nthreads)
int rc;
int n = 10 * 1024 * 1024;
if(qlen <= 0) {
qlen = (n + 127) / 128;
}
a = malloc(n * sizeof(int));
unsigned long long s = 0;
@ -126,8 +130,7 @@ benchmark_quicksort(int serial, int nthreads)
if(serial) {
quicksort_serial(a, 0, n - 1);
} else {
rc = sched_init(nthreads, (n + 127) / 128, quicksort,
new_args(a, 0, n - 1));
rc = sched_init(nthreads, qlen, quicksort, new_args(a, 0, n - 1));
assert(rc >= 0);
}