locked arrowArray in scheduler!

This commit is contained in:
Adrien Bourmault 2021-06-23 09:13:46 +02:00
parent 8c48856994
commit cdacbc0fb6
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
8 changed files with 54 additions and 45 deletions

View File

@ -27,7 +27,7 @@ SRCDIR=src
DEBDIR=debian
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
$(BINDIR)/main.o
$(BINDIR)/main.o $(BINDIR)/arrows.o
CLIOBJ= $(BINDIR)/cli.o
.DEFAULT_GOAL:= all

View File

@ -45,7 +45,7 @@ struct {
struct {
size_t size;
bool lock;
pthread_spinlock_t lock;
Arrow_t *array;
} typedef ArrowArray_t;
@ -81,7 +81,7 @@ struct {
struct {
Space_t *globalDrawingSpace;
IntArray_t *transitionsTree;
ArrowArray_t *arrowList;
ArrowArray_t *arrowArray;
int nmaxThread;
int nmaxCycles;
int ruleRadius;
@ -108,7 +108,7 @@ struct {
Center_t *localWorkAreaCenter;
Space_t *globalDrawingSpace;
IntArray_t *transitionsTree;
ArrowArray_t *arrowList;
ArrowArray_t *arrowArray;
bool pleaseStop;
bool terminated;
int returnValue;

View File

@ -24,3 +24,8 @@
#endif
void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model);
void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowList,
Model_t *model);

View File

@ -37,8 +37,8 @@ static inline void SchedDestroy(Scheduler_t *scheduler)
free(scheduler->globalDrawingSpace->space);
free(scheduler->globalDrawingSpace);
free(scheduler->arrowList->array);
free(scheduler->arrowList);
free(scheduler->arrowArray->array);
free(scheduler->arrowArray);
}
// -------------------------------------------------------------------------- //

View File

@ -22,3 +22,5 @@
#include "../include/base.h"
/* -------------------------------------------------------------------------- */

View File

@ -48,27 +48,15 @@ void *launchScheduler(void *args)
// Creating structure for the model
model0 = (Model_t*) calloc(1, sizeof(Model_t));
model0->space_xmax = XMAX;
model0->siteNumber = SITE_NUMBER;
// Preparing global drawing space
ModelPrepareSpace(scheduler0->globalDrawingSpace, model0);
scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
scheduler0->arrowArray = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
printLog("Populating a random arrow list...\n");
for (int i = 0; i < ARROW_NUMBER; i++) {
if (scheduler0->globalDrawingSpace->xmax)
scheduler0->arrowList->array[i].x =
rand() % (scheduler0->globalDrawingSpace->xmax + 1);
if (scheduler0->globalDrawingSpace->ymax)
scheduler0->arrowList->array[i].y =
rand() % (scheduler0->globalDrawingSpace->ymax + 1);
if (scheduler0->globalDrawingSpace->zmax)
scheduler0->arrowList->array[i].z =
rand() % (scheduler0->globalDrawingSpace->zmax + 1);
}
ModelPrepareArrows(scheduler0->globalDrawingSpace, scheduler0->arrowArray, model0);
scheduler0->nmaxThread = MAX_THREAD;
scheduler0->nmaxCycles = MAX_CYCLES;

View File

@ -20,6 +20,9 @@
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/arrows.h"
static Model_t *loadedModels;
void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model)
{
@ -37,20 +40,18 @@ void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model)
}
}
void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowList,
void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowArray,
Model_t *model)
{
#define ARROW_NUMBER 6
arrowList->array = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t));
arrowList->size = ARROW_NUMBER;
arrowArray->array = (Arrow_t*) calloc(6, sizeof(Arrow_t));
arrowArray->size = 6;
// Creating some arrows
globalDrawingSpace->space[3].sites[1].narrow = 1;
arrowList->array[0].siteId = 1;
arrowList->array[0].x = 3;
arrowArray->array[0].siteId = 1;
arrowArray->array[0].x = 3;
globalDrawingSpace->space[4].sites[0].narrow = 1;
arrowList->array[1].siteId = 0;
arrowList->array[1].x = 4;
arrowArray->array[1].siteId = 0;
arrowArray->array[1].x = 4;
}

View File

@ -22,6 +22,7 @@
#include "../include/base.h"
#include "../include/centers.h"
#include "../include/localworker.h"
#include "../include/arrows.h"
#include <sys/sysinfo.h>
@ -85,7 +86,7 @@ static void *schedulerMain(void *scheduler)
// A cycle is defined as the total renew of all allocated workers.
// 1 cycle = thread * partial cycle.
int nPartialCycles;
int ncpu, nworker;
int ncpu, nworker, err;
// Getting scheduler argument structure
args = (Scheduler_t*) scheduler;
@ -104,6 +105,11 @@ static void *schedulerMain(void *scheduler)
centersList = (Center_t*) calloc(1, sizeof(Center_t));
nPartialCycles = 0;
// Initiate the arrowArray lock
if (err = createArrowLock(args->arrowArray), err != 0) { // TODO destroy this
printLog("Impossible to create the arrow array lock (error %d)\n", err);
return NULL;
}
//
// MAIN LOOP
//
@ -114,9 +120,14 @@ static void *schedulerMain(void *scheduler)
// Create a new thread
if (nworker < ncpu) {
workArea = NULL;
// Acquiring lock to consistently read the arrowArray
if (acquireNonBlockinArrowgLock(args->arrowArray)) { //XXX does not return 0
// Random choice of an arrow
electedArrow =
&args->arrowList->array[rand() % args->arrowList->size];
&args->arrowArray->array[rand() % args->arrowArray->size]; // XXX size is 0
// Find a local area
workArea = findWorkArea(centersList, electedArrow, args->ruleRadius,
@ -125,6 +136,8 @@ static void *schedulerMain(void *scheduler)
args->globalDrawingSpace->ymax,
args->globalDrawingSpace->zmax
);
releaseArrowLock(args->arrowArray);
}
// If a free area exists,
if (workArea) {
@ -141,8 +154,8 @@ static void *schedulerMain(void *scheduler)
args->globalDrawingSpace;
workerArray[i].transitionsTree =
args->transitionsTree;
workerArray[i].arrowList =
args->arrowList;
workerArray[i].arrowArray =
args->arrowArray;
// create the worker,
WorkerInit(&workerArray[i]);
// and increment worker count.