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

Draft
neox wants to merge 24 commits from devel into devel_orig
3 changed files with 36 additions and 23 deletions
Showing only changes of commit 5b4d9f0e2e - Show all commits

View File

@ -135,6 +135,7 @@ struct model_t {
struct worker_t
{
int id;
int thread_num;
int status;
};

View File

@ -36,7 +36,11 @@ 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;
int n_workers;
int workers_per_cycle;
int max_cycles;
int max_workers;
bool pleaseStop;
struct worker_t **workers;
self->id = sched_new_id();
@ -48,33 +52,37 @@ int sched_start (struct scheduler_t *self, struct parameters_t *parameters)
workers = calloc(n_threads, sizeof(struct worker_t*));
//XXX
n_arrows = 1000;
iter_per_cycle = (n_arrows / n_threads) + 1;
n_arrows = 10000000000;
max_cycles = 1;
workers_per_cycle = (n_arrows / n_threads) + 1;
max_workers = workers_per_cycle * max_cycles;
printlog("Needed iteration per cycle (%d arrows to work on) : %d\n",
n_arrows,
iter_per_cycle);
printlog("Need %d workers per cycle (%d arrows to work on) : %d\n",
workers_per_cycle,
n_arrows);
printlog("Start of the simulation cycle\n");
pleaseStop = false;
n_workers = -1;
#pragma omp parallel
{
int thread_num;
thread_num = omp_get_thread_num();
for (int iter = 0; iter < iter_per_cycle; iter++) {
printlog("Start of the thread cycle (iter %d)\n", iter);
while (!pleaseStop) {
/* n_workers++; */
/* if (n_workers > max_workers) { */
/* pleaseStop = true; */
/* } */
#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");
workers[thread_num] = calloc(1, sizeof(struct worker_t));
workers[thread_num]->id = n_workers;
worker_start(workers[thread_num], self);
free(workers[thread_num]);
}
}
printlog("End of simulation\n");
free(workers);

View File

@ -25,6 +25,8 @@
/* -------------------------------------------------------------------------- */
double truc;
static int worker_new_id (void)
{
static int id = 0;
@ -41,7 +43,9 @@ void worker_start(struct worker_t *self, struct scheduler_t *scheduler)
self->id,
random_time);
sleep(random_time);
double a = (double)self->id * 42 / ((double)self->id + 2);
truc = a;
//sleep(random_time);
printlog("Fin du worker %d\n",
self->id);