Scheduler working at maximum perfs

This commit is contained in:
Adrien Bourmault 2021-06-16 00:09:35 +02:00
parent 5862b207ce
commit 51a3fc3719
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 21 additions and 8 deletions

View File

@ -26,6 +26,7 @@
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <sys/param.h>
#define BASE_H

View File

@ -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);

View File

@ -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;

View File

@ -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) {