locked arrowArray in scheduler!
This commit is contained in:
parent
8c48856994
commit
cdacbc0fb6
2
Makefile
2
Makefile
|
@ -27,7 +27,7 @@ SRCDIR=src
|
||||||
DEBDIR=debian
|
DEBDIR=debian
|
||||||
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \
|
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \
|
||||||
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
|
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
|
||||||
$(BINDIR)/main.o
|
$(BINDIR)/main.o $(BINDIR)/arrows.o
|
||||||
CLIOBJ= $(BINDIR)/cli.o
|
CLIOBJ= $(BINDIR)/cli.o
|
||||||
|
|
||||||
.DEFAULT_GOAL:= all
|
.DEFAULT_GOAL:= all
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
size_t size;
|
size_t size;
|
||||||
bool lock;
|
pthread_spinlock_t lock;
|
||||||
Arrow_t *array;
|
Arrow_t *array;
|
||||||
} typedef ArrowArray_t;
|
} typedef ArrowArray_t;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ struct {
|
||||||
struct {
|
struct {
|
||||||
Space_t *globalDrawingSpace;
|
Space_t *globalDrawingSpace;
|
||||||
IntArray_t *transitionsTree;
|
IntArray_t *transitionsTree;
|
||||||
ArrowArray_t *arrowList;
|
ArrowArray_t *arrowArray;
|
||||||
int nmaxThread;
|
int nmaxThread;
|
||||||
int nmaxCycles;
|
int nmaxCycles;
|
||||||
int ruleRadius;
|
int ruleRadius;
|
||||||
|
@ -108,7 +108,7 @@ struct {
|
||||||
Center_t *localWorkAreaCenter;
|
Center_t *localWorkAreaCenter;
|
||||||
Space_t *globalDrawingSpace;
|
Space_t *globalDrawingSpace;
|
||||||
IntArray_t *transitionsTree;
|
IntArray_t *transitionsTree;
|
||||||
ArrowArray_t *arrowList;
|
ArrowArray_t *arrowArray;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
bool terminated;
|
bool terminated;
|
||||||
int returnValue;
|
int returnValue;
|
||||||
|
|
|
@ -24,3 +24,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model);
|
void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model);
|
||||||
|
|
||||||
|
void ModelPrepareArrows(Space_t *globalDrawingSpace, ArrowArray_t *arrowList,
|
||||||
|
Model_t *model);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,8 @@ static inline void SchedDestroy(Scheduler_t *scheduler)
|
||||||
free(scheduler->globalDrawingSpace->space);
|
free(scheduler->globalDrawingSpace->space);
|
||||||
free(scheduler->globalDrawingSpace);
|
free(scheduler->globalDrawingSpace);
|
||||||
|
|
||||||
free(scheduler->arrowList->array);
|
free(scheduler->arrowArray->array);
|
||||||
free(scheduler->arrowList);
|
free(scheduler->arrowArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -22,3 +22,5 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|
22
src/cmds.c
22
src/cmds.c
|
@ -48,27 +48,15 @@ void *launchScheduler(void *args)
|
||||||
// Creating structure for the model
|
// Creating structure for the model
|
||||||
model0 = (Model_t*) calloc(1, sizeof(Model_t));
|
model0 = (Model_t*) calloc(1, sizeof(Model_t));
|
||||||
|
|
||||||
|
model0->space_xmax = XMAX;
|
||||||
|
model0->siteNumber = SITE_NUMBER;
|
||||||
|
|
||||||
// Preparing global drawing space
|
// Preparing global drawing space
|
||||||
ModelPrepareSpace(scheduler0->globalDrawingSpace, model0);
|
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");
|
ModelPrepareArrows(scheduler0->globalDrawingSpace, scheduler0->arrowArray, model0);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduler0->nmaxThread = MAX_THREAD;
|
scheduler0->nmaxThread = MAX_THREAD;
|
||||||
scheduler0->nmaxCycles = MAX_CYCLES;
|
scheduler0->nmaxCycles = MAX_CYCLES;
|
||||||
|
|
19
src/model.c
19
src/model.c
|
@ -20,6 +20,9 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
|
#include "../include/arrows.h"
|
||||||
|
|
||||||
|
static Model_t *loadedModels;
|
||||||
|
|
||||||
void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model)
|
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)
|
Model_t *model)
|
||||||
{
|
{
|
||||||
#define ARROW_NUMBER 6
|
arrowArray->array = (Arrow_t*) calloc(6, sizeof(Arrow_t));
|
||||||
|
arrowArray->size = 6;
|
||||||
arrowList->array = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t));
|
|
||||||
arrowList->size = ARROW_NUMBER;
|
|
||||||
|
|
||||||
// Creating some arrows
|
// Creating some arrows
|
||||||
globalDrawingSpace->space[3].sites[1].narrow = 1;
|
globalDrawingSpace->space[3].sites[1].narrow = 1;
|
||||||
arrowList->array[0].siteId = 1;
|
arrowArray->array[0].siteId = 1;
|
||||||
arrowList->array[0].x = 3;
|
arrowArray->array[0].x = 3;
|
||||||
|
|
||||||
globalDrawingSpace->space[4].sites[0].narrow = 1;
|
globalDrawingSpace->space[4].sites[0].narrow = 1;
|
||||||
arrowList->array[1].siteId = 0;
|
arrowArray->array[1].siteId = 0;
|
||||||
arrowList->array[1].x = 4;
|
arrowArray->array[1].x = 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#include "../include/centers.h"
|
#include "../include/centers.h"
|
||||||
#include "../include/localworker.h"
|
#include "../include/localworker.h"
|
||||||
|
#include "../include/arrows.h"
|
||||||
|
|
||||||
#include <sys/sysinfo.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.
|
// A cycle is defined as the total renew of all allocated workers.
|
||||||
// 1 cycle = thread * partial cycle.
|
// 1 cycle = thread * partial cycle.
|
||||||
int nPartialCycles;
|
int nPartialCycles;
|
||||||
int ncpu, nworker;
|
int ncpu, nworker, err;
|
||||||
|
|
||||||
// Getting scheduler argument structure
|
// Getting scheduler argument structure
|
||||||
args = (Scheduler_t*) scheduler;
|
args = (Scheduler_t*) scheduler;
|
||||||
|
@ -104,6 +105,11 @@ static void *schedulerMain(void *scheduler)
|
||||||
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
||||||
nPartialCycles = 0;
|
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
|
// MAIN LOOP
|
||||||
//
|
//
|
||||||
|
@ -114,17 +120,24 @@ static void *schedulerMain(void *scheduler)
|
||||||
|
|
||||||
// Create a new thread
|
// Create a new thread
|
||||||
if (nworker < ncpu) {
|
if (nworker < ncpu) {
|
||||||
// Random choice of an arrow
|
|
||||||
electedArrow =
|
|
||||||
&args->arrowList->array[rand() % args->arrowList->size];
|
|
||||||
|
|
||||||
// Find a local area
|
workArea = NULL;
|
||||||
workArea = findWorkArea(centersList, electedArrow, args->ruleRadius,
|
|
||||||
args->globalDrawingSpace->size,
|
// Acquiring lock to consistently read the arrowArray
|
||||||
args->globalDrawingSpace->xmax,
|
if (acquireNonBlockinArrowgLock(args->arrowArray)) { //XXX does not return 0
|
||||||
args->globalDrawingSpace->ymax,
|
// Random choice of an arrow
|
||||||
args->globalDrawingSpace->zmax
|
electedArrow =
|
||||||
);
|
&args->arrowArray->array[rand() % args->arrowArray->size]; // XXX size is 0
|
||||||
|
|
||||||
|
// Find a local area
|
||||||
|
workArea = findWorkArea(centersList, electedArrow, args->ruleRadius,
|
||||||
|
args->globalDrawingSpace->size,
|
||||||
|
args->globalDrawingSpace->xmax,
|
||||||
|
args->globalDrawingSpace->ymax,
|
||||||
|
args->globalDrawingSpace->zmax
|
||||||
|
);
|
||||||
|
releaseArrowLock(args->arrowArray);
|
||||||
|
}
|
||||||
|
|
||||||
// If a free area exists,
|
// If a free area exists,
|
||||||
if (workArea) {
|
if (workArea) {
|
||||||
|
@ -141,8 +154,8 @@ static void *schedulerMain(void *scheduler)
|
||||||
args->globalDrawingSpace;
|
args->globalDrawingSpace;
|
||||||
workerArray[i].transitionsTree =
|
workerArray[i].transitionsTree =
|
||||||
args->transitionsTree;
|
args->transitionsTree;
|
||||||
workerArray[i].arrowList =
|
workerArray[i].arrowArray =
|
||||||
args->arrowList;
|
args->arrowArray;
|
||||||
// create the worker,
|
// create the worker,
|
||||||
WorkerInit(&workerArray[i]);
|
WorkerInit(&workerArray[i]);
|
||||||
// and increment worker count.
|
// and increment worker count.
|
||||||
|
|
Loading…
Reference in New Issue