Scheduler working at maximum perfs
This commit is contained in:
parent
5862b207ce
commit
51a3fc3719
|
@ -26,6 +26,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#define BASE_H
|
#define BASE_H
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ static void *LittleWorker(void *worker)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args->returnValue = 0;
|
args->returnValue = a;
|
||||||
args->terminated = true;
|
args->terminated = true;
|
||||||
|
|
||||||
printLog("Worker #%lu offline\n", *args->id);
|
printLog("Worker #%lu offline\n", *args->id);
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define ARROW_NUMBER 150
|
#define ARROW_NUMBER 150
|
||||||
#define MAX_CYCLES 400000
|
#define MAX_CYCLES 15
|
||||||
#define SPACE_SIZE 10000
|
#define SPACE_SIZE 10000
|
||||||
#define MAX_THREAD 0
|
#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->space = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t));
|
||||||
scheduler0->arrowList->size = ARROW_NUMBER;
|
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->nmaxThread = MAX_THREAD;
|
||||||
scheduler0->nmaxCycles = MAX_CYCLES;
|
scheduler0->nmaxCycles = MAX_CYCLES;
|
||||||
|
|
||||||
|
|
|
@ -81,28 +81,30 @@ static void *GreatScheduler(void *scheduler)
|
||||||
Worker_t *workerArray;
|
Worker_t *workerArray;
|
||||||
Center_t *centersList, *workArea;
|
Center_t *centersList, *workArea;
|
||||||
Arrow_t *electedArrow;
|
Arrow_t *electedArrow;
|
||||||
int ncycles;
|
int nPartialCycles; // 1 cycle = thread * partial cycle
|
||||||
int ncpu, nworker;
|
int ncpu, nworker;
|
||||||
|
|
||||||
// Getting scheduler argument structure
|
// Getting scheduler argument structure
|
||||||
args = (Scheduler_t*) scheduler;
|
args = (Scheduler_t*) scheduler;
|
||||||
printLog("Scheduler #%lu online\n", *args->id);
|
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);
|
printLog("%d CPUs available.\n", ncpu);
|
||||||
|
|
||||||
// Data structures
|
// Data structures
|
||||||
workerArray = (Worker_t*) calloc(ncpu, sizeof(Worker_t));
|
workerArray = (Worker_t*) calloc(ncpu, sizeof(Worker_t));
|
||||||
nworker = 0;
|
nworker = 0;
|
||||||
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
||||||
ncycles = 0;
|
nPartialCycles = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// MAIN LOOP
|
// MAIN LOOP
|
||||||
//
|
//
|
||||||
while (!args->pleaseStop && ncycles <= args->nmaxCycles) {
|
while (!args->pleaseStop && (nPartialCycles / ncpu) <= args->nmaxCycles) {
|
||||||
// Increment cycles
|
|
||||||
ncycles++;
|
|
||||||
//printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles);
|
//printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles);
|
||||||
|
|
||||||
// XXX statistics here
|
// XXX statistics here
|
||||||
|
@ -137,6 +139,8 @@ static void *GreatScheduler(void *scheduler)
|
||||||
workArea,
|
workArea,
|
||||||
nworker
|
nworker
|
||||||
);
|
);
|
||||||
|
// Increment partial cycle
|
||||||
|
nPartialCycles++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,6 +170,7 @@ static void *GreatScheduler(void *scheduler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exiting scheduler properly
|
// Exiting scheduler properly
|
||||||
|
printLog("Stopping scheduler... (waiting for workers)\n");
|
||||||
// Waiting for remaining workers
|
// Waiting for remaining workers
|
||||||
for (int i = 0; i < ncpu; i++) {
|
for (int i = 0; i < ncpu; i++) {
|
||||||
if (workerArray[i].id) {
|
if (workerArray[i].id) {
|
||||||
|
|
Loading…
Reference in New Issue