WIP: trying loop performances
This commit is contained in:
parent
cb434fc4dc
commit
5b4d9f0e2e
|
@ -135,6 +135,7 @@ struct model_t {
|
||||||
struct worker_t
|
struct worker_t
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
int thread_num;
|
||||||
int status;
|
int status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,11 @@ int sched_start (struct scheduler_t *self, struct parameters_t *parameters)
|
||||||
{
|
{
|
||||||
int n_threads = omp_get_max_threads();
|
int n_threads = omp_get_max_threads();
|
||||||
int n_arrows;
|
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;
|
struct worker_t **workers;
|
||||||
|
|
||||||
self->id = sched_new_id();
|
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*));
|
workers = calloc(n_threads, sizeof(struct worker_t*));
|
||||||
|
|
||||||
//XXX
|
//XXX
|
||||||
n_arrows = 1000;
|
n_arrows = 10000000000;
|
||||||
iter_per_cycle = (n_arrows / n_threads) + 1;
|
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",
|
printlog("Need %d workers per cycle (%d arrows to work on) : %d\n",
|
||||||
n_arrows,
|
workers_per_cycle,
|
||||||
iter_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++) {
|
while (!pleaseStop) {
|
||||||
printlog("Start of the thread cycle (iter %d)\n", iter);
|
/* n_workers++; */
|
||||||
|
/* if (n_workers > max_workers) { */
|
||||||
|
/* pleaseStop = true; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
#pragma omp parallel
|
workers[thread_num] = calloc(1, sizeof(struct worker_t));
|
||||||
{
|
workers[thread_num]->id = n_workers;
|
||||||
int thread_num;
|
worker_start(workers[thread_num], self);
|
||||||
thread_num = omp_get_thread_num();
|
free(workers[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");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printlog("End of simulation\n");
|
||||||
|
|
||||||
free(workers);
|
free(workers);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
double truc;
|
||||||
|
|
||||||
static int worker_new_id (void)
|
static int worker_new_id (void)
|
||||||
{
|
{
|
||||||
static int id = 0;
|
static int id = 0;
|
||||||
|
@ -41,7 +43,9 @@ void worker_start(struct worker_t *self, struct scheduler_t *scheduler)
|
||||||
self->id,
|
self->id,
|
||||||
random_time);
|
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",
|
printlog("Fin du worker %d\n",
|
||||||
self->id);
|
self->id);
|
||||||
|
|
Loading…
Reference in New Issue