Changeset 60 for sources/src/gen_code.cc


Ignore:
Timestamp:
Feb 14, 2017, 11:30:19 AM (8 years ago)
Author:
meunier
Message:
  • Intégration des modifications de Clément, qui a intégré la version parallélisée de systemcass faite par Manuel.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/gen_code.cc

    r59 r60  
    4949#include <iostream>
    5050#include <fstream>
     51#ifdef _OPENMP
     52#include <omp.h>
     53#endif
    5154
    5255#include "internal.h"
     
    5861#ifdef HAVE_CONFIG_H
    5962#include "config.h"
    60 #endif
    61 
    62 #ifdef _OPENMP
    63 #include <omp.h>
    6463#endif
    6564
     
    246245        method_process_list_t &
    247246        moore_func_list,
    248         strong_component_list_t &
     247        strong_component_list_t *
    249248        strongcomponents) {
    250249    if (dump_stage) {
     
    277276    gen_transition(o, transition_func_list);
    278277    gen_moore(o, moore_func_list);
    279     gen_mealy(o, strongcomponents);
     278    if (strongcomponents != NULL) {
     279        gen_mealy      (o, *strongcomponents);
     280    }
    280281
    281282    o << " \n}\n";
     
    575576 */
    576577
    577 static method_process_list_t func_list[2];
     578unsigned int nb_func[2];
     579static method_process_t **func_list[2];
     580#pragma omp threadprivate (nb_func, func_list)
    578581static strong_component_list_t quasistatic_list;
     582
     583unsigned long long busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml;
     584unsigned long long last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml;
     585#pragma omp threadprivate (busy_wait_f0, busy_wait_f1, busy_wait_up,busy_wait_ml)
     586#pragma omp threadprivate (last_wait_f0, last_wait_f1, last_wait_up,last_wait_ml)
    579587
    580588static void Call(const method_process_t & m) {
     
    611619}
    612620
     621unsigned int expected_globaltime = 0;
     622volatile unsigned int globaltime __attribute__ ((aligned (128))) = 0;
     623#pragma omp shared (globaltime)
     624#pragma omp threadprivate (expected_globaltime)
     625
     626unsigned int num_omp_threads;
    613627
    614628void quasistatic_simulate_1_cycle(void) {
    615     method_process_list_t::iterator mm;
    616     for (mm = func_list[0].begin(); mm != func_list[0].end(); ++mm) {
    617         method_process_t & m = **mm;
    618         Call(m);
    619     }
     629    int i;
     630
     631    for (i = 0; i < nb_func[0]; ++i) {
     632        Call(*(func_list[0][i]));
     633    }
     634#define USE_BUSY_WAIT 1
    620635    update();
    621     for (mm = func_list[1].begin(); mm != func_list[1].end(); ++mm) {
    622         method_process_t & m = **mm;
    623         Call(m);
    624     }
    625     quasistatic_mealy_generation();
     636#if USE_BUSY_WAIT
     637    expected_globaltime += num_omp_threads;
     638    if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
     639        last_wait_up++;
     640    }
     641    __asm volatile("mfence");
     642    while (globaltime < expected_globaltime) {
     643        busy_wait_up++;
     644        __asm volatile("lfence");
     645    }
     646
     647#else
     648#pragma omp barrier
     649#endif
     650
     651    for (i = 0; i < nb_func[1]; ++i) {
     652        Call(*(func_list[1][i]));
     653    }
     654
     655#if USE_BUSY_WAIT
     656    expected_globaltime += num_omp_threads;
     657    if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
     658        last_wait_f1++;
     659    }
     660    __asm volatile("mfence");
     661    while (globaltime < expected_globaltime) {
     662        busy_wait_f1++;
     663        __asm volatile("lfence");
     664    }
     665#else
     666#pragma omp barrier
     667#endif
     668    if (!quasistatic_list.empty()) {
     669#pragma omp master
     670        {
     671            quasistatic_mealy_generation();
     672        }
     673#if USE_BUSY_WAIT
     674        expected_globaltime += num_omp_threads;
     675        if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
     676            last_wait_ml++;
     677        }
     678        __asm volatile("mfence");
     679        while (globaltime < expected_globaltime) {
     680            busy_wait_ml++;
     681            __asm volatile("lfence");
     682        }
     683#else
     684#pragma omp barrier
     685#endif
     686    }
     687
    626688}
    627689
     
    631693        method_process_list_t &
    632694        moore_func_list,
    633         strong_component_list_t &
     695        strong_component_list_t *
    634696        mealy_func_list) {
    635697    if (dump_stage) {
     
    637699    }
    638700
    639     func_list[0] = transition_func_list;
    640     func_list[1] = moore_func_list;
    641     quasistatic_list = mealy_func_list;
     701    nb_func[0] = transition_func_list.size();
     702    nb_func[1] = moore_func_list.size();
     703
     704    func_list[0] = (method_process_t**) malloc(sizeof (method_process_t*) * nb_func[0]);
     705    func_list[1] = (method_process_t**) malloc(sizeof (method_process_t*) * nb_func[1]);
     706
     707    unsigned int i;
     708    for (i = 0; i < nb_func[0]; ++i) {
     709        func_list[0][i] = (transition_func_list[i]);
     710    }
     711
     712    for (i = 0; i < nb_func[1]; ++i) {
     713        func_list[1][i] = (moore_func_list[i]);
     714    }
     715
     716    if (mealy_func_list != NULL) {
     717        quasistatic_list = *mealy_func_list;
     718    }
    642719
    643720    if (dump_stage) {
Note: See TracChangeset for help on using the changeset viewer.