WIP: devel : travail du mois de mars/avril #28

Draft
neox wants to merge 24 commits from devel into devel_orig
14 changed files with 222 additions and 85 deletions
Showing only changes of commit cb434fc4dc - Show all commits

View File

@ -22,7 +22,6 @@
#include <sys/param.h>
#include <stdbool.h>
#include <pthread.h>
#include <assert.h>
#include <unistd.h>
#include <malloc.h>
@ -31,16 +30,21 @@
#include <errno.h>
#include <stdio.h>
#include <netinet/in.h>
#include <omp.h>
#define BASE_H
/* -------------------------------------------------------------------------- */
#define LOGMSG "<%s:%s()>"
#define printlog(FORMAT, ...) printf("\e[0m" LOGMSG " " FORMAT "\e[0m", \
__FILE__,__func__, ##__VA_ARGS__)
#define printerr(FORMAT,...) fprintf(stderr, "\e[0m" LOGMSG " " FORMAT "\e[0m",\
__FILE__,__func__, ##__VA_ARGS__)
#define printlog(FORMAT, ...) printf("\e[0;36m" LOGMSG "\e[0m" " " FORMAT \
"\e[0m", __FILE__,__func__, ##__VA_ARGS__)
#define printerr(FORMAT,...) fprintf(stderr, "\e[0;31m" LOGMSG "\e[0m" " " \
FORMAT "\e[0m", __FILE__,__func__, \
##__VA_ARGS__)
#define LEN(x) (sizeof(x) / sizeof((x)[0]))
/* -------------------------------------------------------------------------- */
@ -63,12 +67,79 @@ struct arrow_t {
uint z;
};
struct model_t {
struct space_unit_t
{
bool lock;
struct arrow_t **sites; // Array of struct arrow_t* elements
// - lenght is multiplicity
};
struct space_t
{
// Dimensions of space.
// Note that a value 0 is not allowed, minimum is 1
int x_dim;
int y_dim;
int z_dim;
struct space_unit_t *units; // (flat) arraw of space_unit_t elements :
// - lenght is x_dim * y_dim * z_dim
// - access to the (x,y,z) is done by
// units[ x
// + dim_x * y
// + dim_x * dim_y * z ]
};
struct state_t
{
// Metadata
int id;
}
int owner_id;
time_t date;
struct space_t *space;
};
struct model_t {
// Metadata
int id;
int owner_id;
time_t date;
union version
{
int major;
int minor;
};
// User friendly metadata
char *owner_name;
char *model_name;
// Model parameters
int multiplicity; // number of sites in a space_unit
int dimension; // number of space dimensions
// Simulation parameters
int max_thread;
int max_cycles;
// Handler to the current space of the model
struct space_t *space;
// Handler to the saved states of the model
struct state_t **states;
};
struct worker_t
{
int id;
int status;
};
struct scheduler_t
{
int id;
struct model_t *models;
struct model_t **model; // Queue (array) of waiting models
};

View File

@ -1,30 +0,0 @@
//=-------------------------------------------------------------------------=//
// Local workers definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */

View File

@ -48,17 +48,6 @@
/* -------------------------------------------------------------------------- */
bool model_init(const char *content, size_t length, const char *basename);
bool model_shutdown(void);
char model_get_dim(void);
long model_get_dim_value(const char *axis);
char model_get_multiplicity(void);
bool model_get_next_state(char *new_state_id);
bool model_get_next_arrow(struct arrow_t *new_arrow,
const char *state_id,
char dimension);
// -------------------------------------------------------------------------- //
// Model init function (and model discovery) //
// -------------------------------------------------------------------------- //
@ -74,11 +63,15 @@ bool model_get_next_arrow(struct arrow_t *new_arrow,
// -------------------------------------------------------------------------- //
// int model_load (int id);
bool model_init(const char *content, size_t length, const char *basename);
// -------------------------------------------------------------------------- //
// Unload a model //
// -------------------------------------------------------------------------- //
// int model_unload (int id);
bool model_shutdown(void);
// -------------------------------------------------------------------------- //
// Add a model to the known model list //
// -------------------------------------------------------------------------- //
@ -103,3 +96,19 @@ bool model_get_next_arrow(struct arrow_t *new_arrow,
// Stop and unload all loaded or running model //
// -------------------------------------------------------------------------- //
// void model_shutdown (void);
// -------------------------------------------------------------------------- //
// Parsing primitives //
// -------------------------------------------------------------------------- //
char model_get_dim(void);
long model_get_dim_value(const char *axis);
char model_get_multiplicity(void);
bool model_get_next_state(char *new_state_id);
bool model_get_next_arrow(struct arrow_t *new_arrow,
const char *state_id,
char dimension);

View File

@ -29,10 +29,24 @@
/* -------------------------------------------------------------------------- */
enum
{
// quitting values
SCHED_NORMAL_EXIT,
SCHED_OMP_ERROR,
SCHED_UNKNOWN_ERROR,
// non-quitting / non-fatal errors
SCHED_NON_FATAL_ERRORS, //meta-code
SCHED_MODEL_ERROR,
SCHED_CONTINUE
};
// -------------------------------------------------------------------------- //
// Scheduler init function //
// Scheduler main function //
// -------------------------------------------------------------------------- //
void sched_init(struct scheduler_t *scheduler);
int sched_start (struct scheduler_t *scheduler, struct parameters_t *parameters);
// -------------------------------------------------------------------------- //
// Scheduler content destructor function //

View File

@ -27,10 +27,24 @@
/* -------------------------------------------------------------------------- */
enum
{
// quitting values
WORKER_NORMAL_EXIT,
WORKER_OMP_ERROR,
WORKER_UNKNOWN_ERROR,
// non-quitting / non-fatal errors
WORKER_NON_FATAL_ERRORS, //meta-code
WORKER_MODEL_ERROR,
WORKER_CONTINUE
};
// -------------------------------------------------------------------------- //
// Worker init function //
// -------------------------------------------------------------------------- //
//void worker_init(worker_t *worker);
void worker_start(struct worker_t *worker, struct scheduler_t *scheduler);
// -------------------------------------------------------------------------- //
// Worker destructor function //

View File

@ -22,5 +22,6 @@
"glib"
"mesa-headers"
"mesa"
"libomp"
)
)

View File

@ -1,27 +0,0 @@
//=-------------------------------------------------------------------------=//
// Centers management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/centers.h"
/* -------------------------------------------------------------------------- */

View File

@ -20,6 +20,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/cmds.h"
#include "../include/scheduler.h"
#include "../include/model.h"

View File

@ -21,8 +21,7 @@
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/server.h"
#include "../include/model.h"
#include "../include/scheduler.h"
/* -------------------------------------------------------------------------- */
@ -41,8 +40,9 @@ int main(int argc, char **argv)
{
int options;
time_t t;
int returnValue = 0;
int returnValue = SCHED_CONTINUE;
struct parameters_t parameters = {0};
struct scheduler_t scheduler = {0};
while ((options = getopt(argc, argv, ":C:M:U:")) != -1) {
switch (options) {
@ -133,6 +133,10 @@ int main(int argc, char **argv)
/* free(server); */
/* server = NULL; */
while (returnValue > SCHED_NON_FATAL_ERRORS) {
returnValue = sched_start (&scheduler, &parameters);
}
free(parameters.userDir);
free(parameters.modelDir);
free(parameters.configDir);

View File

@ -20,6 +20,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/model.h"
#include "../include/arrows.h"
#include "../include/scheduler.h"
@ -33,6 +34,8 @@
#define SUCCESSFUL_READ_ARROW_XY (READ_SITE | READ_WEIGHT | READ_X | READ_Y)
#define SUCCESSFUL_READ_ARROW_XYZ (READ_SITE | READ_WEIGHT | READ_X | READ_Y | READ_Z)
/* -------------------------------------------------------------------------- */
static xmlDocPtr model;
static xmlHashTablePtr model_hashtable;

View File

@ -20,11 +20,63 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/scheduler.h"
#include "../include/centers.h"
#include "../include/worker.h"
#include "../include/arrows.h"
#include <sys/sysinfo.h>
/* -------------------------------------------------------------------------- */
static int sched_new_id (void)
{
static int id = 0;
return id;
}
int sched_start (struct scheduler_t *self, struct parameters_t *parameters)
{
int n_threads = omp_get_max_threads();
int n_arrows;
int iter_per_cycle;
struct worker_t **workers;
self->id = sched_new_id();
printlog("Hey, I'm the scheduler %d and I can work with %d threads !\n",
self->id,
n_threads);
workers = calloc(n_threads, sizeof(struct worker_t*));
//XXX
n_arrows = 1000;
iter_per_cycle = (n_arrows / n_threads) + 1;
printlog("Needed iteration per cycle (%d arrows to work on) : %d\n",
n_arrows,
iter_per_cycle);
printlog("Start of the simulation cycle\n");
for (int iter = 0; iter < iter_per_cycle; iter++) {
printlog("Start of the thread cycle (iter %d)\n", iter);
#pragma omp parallel
{
int thread_num;
thread_num = omp_get_thread_num();
workers[thread_num] = calloc(1, sizeof(struct worker_t));
workers[thread_num]->id = thread_num;
worker_start(workers[thread_num], self);
free(workers[thread_num]);
}
printlog("End of the thread cycle\n");
}
free(workers);
return SCHED_NORMAL_EXIT;
}

View File

@ -20,6 +20,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/server.h"
#include "../include/cmds.h"

View File

@ -20,6 +20,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/supervisor.h"
/* -------------------------------------------------------------------------- */

View File

@ -20,8 +20,31 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/worker.h"
/* -------------------------------------------------------------------------- */
static int worker_new_id (void)
{
static int id = 0;
return id;
}
void worker_start(struct worker_t *self, struct scheduler_t *scheduler)
{
unsigned int random_time;
random_time = (unsigned int)(rand() % 2);
printlog("Coucou, c'est le worker %d (et je vais dormir %d s)\n",
self->id,
random_time);
sleep(random_time);
printlog("Fin du worker %d\n",
self->id);
self->status = WORKER_NORMAL_EXIT;
}