From 51a3fc37199f46e6d4325f3dc168328c9500704a Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 16 Jun 2021 00:09:35 +0200 Subject: [PATCH] Scheduler working at maximum perfs --- include/base.h | 1 + src/localworker.c | 2 +- src/main.c | 9 ++++++++- src/scheduler.c | 17 +++++++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/base.h b/include/base.h index f1fff61..6553fad 100644 --- a/include/base.h +++ b/include/base.h @@ -26,6 +26,7 @@ #include #include #include +#include #define BASE_H diff --git a/src/localworker.c b/src/localworker.c index 72e9262..44692a3 100644 --- a/src/localworker.c +++ b/src/localworker.c @@ -54,7 +54,7 @@ static void *LittleWorker(void *worker) } } - args->returnValue = 0; + args->returnValue = a; args->terminated = true; printLog("Worker #%lu offline\n", *args->id); diff --git a/src/main.c b/src/main.c index 05c8158..93a1f92 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,7 @@ #define ARROW_NUMBER 150 -#define MAX_CYCLES 400000 +#define MAX_CYCLES 15 #define SPACE_SIZE 10000 #define MAX_THREAD 0 @@ -57,6 +57,13 @@ int main(int argc, char **argv) scheduler0->arrowList->space = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t)); scheduler0->arrowList->size = ARROW_NUMBER; + printLog("Populating a random arrow list...\n"); + for (int i = 0; i < ARROW_NUMBER; i++) { + scheduler0->arrowList->space[i].x = rand() % SPACE_SIZE; + scheduler0->arrowList->space[i].y = rand() % SPACE_SIZE; + scheduler0->arrowList->space[i].z = rand() % SPACE_SIZE; + } + scheduler0->nmaxThread = MAX_THREAD; scheduler0->nmaxCycles = MAX_CYCLES; diff --git a/src/scheduler.c b/src/scheduler.c index 3b686b6..6d793ff 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -81,28 +81,30 @@ static void *GreatScheduler(void *scheduler) Worker_t *workerArray; Center_t *centersList, *workArea; Arrow_t *electedArrow; - int ncycles; + int nPartialCycles; // 1 cycle = thread * partial cycle int ncpu, nworker; // Getting scheduler argument structure args = (Scheduler_t*) scheduler; printLog("Scheduler #%lu online\n", *args->id); - ncpu = get_nprocs() * 3; + if (!args->nmaxThread) { + ncpu = get_nprocs(); + } else { + ncpu = MIN(get_nprocs(), args->nmaxThread); + } printLog("%d CPUs available.\n", ncpu); // Data structures workerArray = (Worker_t*) calloc(ncpu, sizeof(Worker_t)); nworker = 0; centersList = (Center_t*) calloc(1, sizeof(Center_t)); - ncycles = 0; + nPartialCycles = 0; // // MAIN LOOP // - while (!args->pleaseStop && ncycles <= args->nmaxCycles) { - // Increment cycles - ncycles++; + while (!args->pleaseStop && (nPartialCycles / ncpu) <= args->nmaxCycles) { //printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles); // XXX statistics here @@ -137,6 +139,8 @@ static void *GreatScheduler(void *scheduler) workArea, nworker ); + // Increment partial cycle + nPartialCycles++; break; } } @@ -166,6 +170,7 @@ static void *GreatScheduler(void *scheduler) } // Exiting scheduler properly + printLog("Stopping scheduler... (waiting for workers)\n"); // Waiting for remaining workers for (int i = 0; i < ncpu; i++) { if (workerArray[i].id) {