From f4711dab2557794508a024856ed67a097f929b15 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 11 Jun 2021 15:11:06 +0200 Subject: [PATCH 1/3] printLog macro --- include/base.h | 4 ++++ src/main.c | 2 ++ src/scheduler.c | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/base.h b/include/base.h index 2163269..ac1642a 100644 --- a/include/base.h +++ b/include/base.h @@ -24,6 +24,7 @@ #include #include #include +#include #define BASE_H @@ -37,6 +38,9 @@ struct { int *space; } typedef IntArray_t; +#define LOGMSG "[%s]" +#define printLog(FORMAT, ...) printf(LOGMSG " " FORMAT, __func__, ##__VA_ARGS__) + // // Scheduler // diff --git a/src/main.c b/src/main.c index 6be34a5..154547e 100644 --- a/src/main.c +++ b/src/main.c @@ -53,6 +53,8 @@ void SchedulerCrashTest(void) int main(int argc, char **argv) { + printLog("Starting gem-graph-server...\n"); + // // Creating parameters structure for the Scheduler // diff --git a/src/scheduler.c b/src/scheduler.c index 1b943df..27156e8 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -22,6 +22,8 @@ #include "../include/base.h" #include "../include/localworker.h" +#include + static void *GreatScheduler(void *parameters); /* -------------------------------------------------------------------------- */ @@ -41,9 +43,13 @@ pthread_t *SchedInit(SchedulerParams_t *parameters) // -------------------------------------------------------------------------- // static void *GreatScheduler(void *params) { + // récupération des paramètres et annonce SchedulerParams_t *parameters = (SchedulerParams_t*) params; + printLog("Scheduler id %lu: I'm alive!\n", *(parameters->id)); + + int ncpu = get_nprocs(); + printLog("%d CPUs available.\n", ncpu); - printf("Scheduler id %p: I'm alive!\n", parameters->id); return NULL; } From b73a9a80915e3e5530c585c4d3ea5effeb882970 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 11 Jun 2021 16:50:38 +0200 Subject: [PATCH 2/3] Center list --- include/base.h | 15 +++++++++------ src/scheduler.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/include/base.h b/include/base.h index ac1642a..9412f15 100644 --- a/include/base.h +++ b/include/base.h @@ -62,13 +62,16 @@ struct { // // Local threads // -struct { - int x; - int y; - int z; +struct Center_t { + int x; + int y; + int z; + + struct Center_t *next; + struct Center_t *prev; } typedef Center_t; struct { - pthread_t *id; - Center_t *localWorkAreaCenter; + pthread_t *id; + Center_t *localWorkAreaCenter; } typedef Thread_t; diff --git a/src/scheduler.c b/src/scheduler.c index 27156e8..184a219 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -38,6 +38,43 @@ pthread_t *SchedInit(SchedulerParams_t *parameters) return parameters->id; } +// -------------------------------------------------------------------------- // +// Center_t management functions // +// -------------------------------------------------------------------------- // +static inline void centerAssign(Center_t *center, int x, int y, int z) +{ + center->x = x; + center->y = y; + center->z = z; +} + +static inline Center_t *centerAdd(Center_t *anyCenter) +{ + Center_t *newCenter = (Center_t*) malloc(sizeof(Center_t)); + + Center_t *temp = anyCenter->next; + anyCenter->next = newCenter; + newCenter->next = temp; + newCenter->prev = anyCenter; + + if (temp) { + temp->prev = newCenter; + } + + return newCenter; +} + +static inline void centerRemove(Center_t *oldCenter) +{ + Center_t *prev = oldCenter->prev; + Center_t *next = oldCenter->next; + + prev->next = next->prev; + next->prev = prev->next; + + free(oldCenter); +} + // -------------------------------------------------------------------------- // // Scheduler thread main function // // -------------------------------------------------------------------------- // @@ -45,11 +82,15 @@ static void *GreatScheduler(void *params) { // récupération des paramètres et annonce SchedulerParams_t *parameters = (SchedulerParams_t*) params; - printLog("Scheduler id %lu: I'm alive!\n", *(parameters->id)); + printLog("Scheduler id %lu: Bonjour I'm the boss !\n", *(parameters->id)); int ncpu = get_nprocs(); printLog("%d CPUs available.\n", ncpu); + Thread_t *workerArray = (Thread_t*) malloc(sizeof(Thread_t) * 3 * ncpu); + Center_t *centersArray = (Center_t*) malloc(sizeof(Center_t)); + + centerAssign(centersArray, -1, -1, -1); return NULL; } From 2182233068980a2a63690b51f33f46baaeb4a61b Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 11 Jun 2021 16:51:07 +0200 Subject: [PATCH 3/3] Center list --- src/scheduler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 184a219..b3a02ef 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -88,9 +88,9 @@ static void *GreatScheduler(void *params) printLog("%d CPUs available.\n", ncpu); Thread_t *workerArray = (Thread_t*) malloc(sizeof(Thread_t) * 3 * ncpu); - Center_t *centersArray = (Center_t*) malloc(sizeof(Center_t)); + Center_t *centersList = (Center_t*) malloc(sizeof(Center_t)); - centerAssign(centersArray, -1, -1, -1); + centerAssign(centersList, -1, -1, -1); return NULL; }