diff --git a/includes/mandelbrot.h b/includes/mandelbrot.h index 724dfbf..543f69f 100644 --- a/includes/mandelbrot.h +++ b/includes/mandelbrot.h @@ -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); diff --git a/includes/quicksort.h b/includes/quicksort.h index 84e7a93..9f815d3 100644 --- a/includes/quicksort.h +++ b/includes/quicksort.h @@ -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); diff --git a/src/main.c b/src/main.c index dbcbd08..0fd48b7 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/mandelbrot.c b/src/mandelbrot.c index 946cf4e..4833194 100644 --- a/src/mandelbrot.c +++ b/src/mandelbrot.c @@ -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); } diff --git a/src/quicksort.c b/src/quicksort.c index d4701a8..b996489 100644 --- a/src/quicksort.c +++ b/src/quicksort.c @@ -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); }