reformat, following initial convention
This commit is contained in:
parent
f95dcaf491
commit
6b891cf338
5 changed files with 266 additions and 241 deletions
5
.clang-format
Normal file
5
.clang-format
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
IndentWidth: 4
|
||||||
|
InsertBraces: true
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
AlwaysBreakAfterReturnType: TopLevelDefinitions
|
||||||
|
SpaceBeforeParens: Never
|
|
@ -31,7 +31,9 @@ struct scheduler {
|
||||||
int exit;
|
int exit;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int sched_default_threads(void) {
|
static inline int
|
||||||
|
sched_default_threads(void)
|
||||||
|
{
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "../includes/quicksort.h"
|
#include "../includes/quicksort.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
return benchmark(argc, argv);
|
return benchmark(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "../includes/quicksort.h"
|
#include "../includes/quicksort.h"
|
||||||
|
|
||||||
int partition(int *a, int lo, int hi) {
|
int
|
||||||
|
partition(int *a, int lo, int hi)
|
||||||
|
{
|
||||||
int pivot = a[lo];
|
int pivot = a[lo];
|
||||||
int i = lo - 1;
|
int i = lo - 1;
|
||||||
int j = hi + 1;
|
int j = hi + 1;
|
||||||
|
@ -29,7 +31,9 @@ struct quicksort_args {
|
||||||
int lo, hi;
|
int lo, hi;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct quicksort_args *new_args(int *a, int lo, int hi) {
|
struct quicksort_args *
|
||||||
|
new_args(int *a, int lo, int hi)
|
||||||
|
{
|
||||||
struct quicksort_args *args = malloc(sizeof(struct quicksort_args));
|
struct quicksort_args *args = malloc(sizeof(struct quicksort_args));
|
||||||
if(args == NULL) {
|
if(args == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -41,7 +45,9 @@ struct quicksort_args *new_args(int *a, int lo, int hi) {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
void quicksort_serial(int *a, int lo, int hi) {
|
void
|
||||||
|
quicksort_serial(int *a, int lo, int hi)
|
||||||
|
{
|
||||||
int p;
|
int p;
|
||||||
|
|
||||||
if(lo >= hi) {
|
if(lo >= hi) {
|
||||||
|
@ -53,7 +59,9 @@ void quicksort_serial(int *a, int lo, int hi) {
|
||||||
quicksort_serial(a, p + 1, hi);
|
quicksort_serial(a, p + 1, hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void quicksort(void *closure, struct scheduler *s) {
|
void
|
||||||
|
quicksort(void *closure, struct scheduler *s)
|
||||||
|
{
|
||||||
struct quicksort_args *args = (struct quicksort_args *)closure;
|
struct quicksort_args *args = (struct quicksort_args *)closure;
|
||||||
int *a = args->a;
|
int *a = args->a;
|
||||||
int lo = args->lo;
|
int lo = args->lo;
|
||||||
|
@ -79,7 +87,9 @@ void quicksort(void *closure, struct scheduler *s) {
|
||||||
assert(rc >= 0);
|
assert(rc >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int benchmark(int argc, char **argv) {
|
int
|
||||||
|
benchmark(int argc, char **argv)
|
||||||
|
{
|
||||||
int *a;
|
int *a;
|
||||||
struct timespec begin, end;
|
struct timespec begin, end;
|
||||||
double delay;
|
double delay;
|
||||||
|
@ -128,8 +138,8 @@ int benchmark(int argc, char **argv) {
|
||||||
if(serial) {
|
if(serial) {
|
||||||
quicksort_serial(a, 0, n - 1);
|
quicksort_serial(a, 0, n - 1);
|
||||||
} else {
|
} else {
|
||||||
rc =
|
rc = sched_init(nthreads, (n + 127) / 128, quicksort,
|
||||||
sched_init(nthreads, (n + 127) / 128, quicksort, new_args(a, 0, n - 1));
|
new_args(a, 0, n - 1));
|
||||||
assert(rc >= 0);
|
assert(rc >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/sched.c
12
src/sched.c
|
@ -6,7 +6,9 @@
|
||||||
static struct scheduler sched;
|
static struct scheduler sched;
|
||||||
|
|
||||||
/* Lance une tâche de la pile */
|
/* Lance une tâche de la pile */
|
||||||
void *worker_routine(void *arg) {
|
void *
|
||||||
|
worker_routine(void *arg)
|
||||||
|
{
|
||||||
struct scheduler *s = (struct scheduler *)arg;
|
struct scheduler *s = (struct scheduler *)arg;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
@ -51,7 +53,9 @@ void *worker_routine(void *arg) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sched_init(int nthreads, int qlen, taskfunc f, void *closure) {
|
int
|
||||||
|
sched_init(int nthreads, int qlen, taskfunc f, void *closure)
|
||||||
|
{
|
||||||
if(nthreads == 0) {
|
if(nthreads == 0) {
|
||||||
nthreads = sched_default_threads();
|
nthreads = sched_default_threads();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +100,9 @@ int sched_init(int nthreads, int qlen, taskfunc f, void *closure) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sched_spawn(taskfunc f, void *closure, struct scheduler *s) {
|
int
|
||||||
|
sched_spawn(taskfunc f, void *closure, struct scheduler *s)
|
||||||
|
{
|
||||||
pthread_mutex_lock(&s->mutex);
|
pthread_mutex_lock(&s->mutex);
|
||||||
|
|
||||||
if(s->top + 1 >= MAX_TASKS) {
|
if(s->top + 1 >= MAX_TASKS) {
|
||||||
|
|
Reference in a new issue