Changeset 65 for sources/src/gen_code.h


Ignore:
Timestamp:
Oct 23, 2019, 12:53:07 PM (5 years ago)
Author:
bouyer
Message:

Various performance improvements for the parallel systemcass: cache-aligned
data structures, write only when needed, disable some unneeded barriers.

Fix bug in the non-openmp case: a pointer was not initialized

various style updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/gen_code.h

    r63 r65  
    4242/* generate a scheduling code */
    4343extern void  gen_scheduling_code_for_quasistatic_func(
    44       method_process_list_t   &transition_list,
    45       method_process_list_t   &moore_list,
    46       strong_component_list_t *mealy_list);
    47 
     44                      method_process_list_t   &transition_list,
     45                      method_process_list_t   &moore_list,
     46                            strong_component_list_t *mealy_list);
    4847extern void  gen_scheduling_code_for_static_func(
    49       method_process_list_t   &transition_list,
    50       method_process_list_t   &moore_list,
    51       ProcessDependencyList   &mealy_list);
     48                      method_process_list_t   &transition_list,
     49                      method_process_list_t   &moore_list,
     50                            ProcessDependencyList   &mealy_list);
     51extern char *gen_scheduling_code_for_dynamic_link(
     52                      method_process_list_t   &transition_list,
     53                      method_process_list_t   &moore_list,
     54                            ProcessDependencyList   &mealy_list);
     55extern char *gen_scheduling_code_for_dynamic_link(
     56                      method_process_list_t   &transition_list,
     57                      method_process_list_t   &moore_list,
     58                            strong_component_list_t *strongcomponents);
    5259
    5360extern char * gen_scheduling_code_for_dynamic_link(
     
    8794#pragma omp master
    8895    {
    89         std::cerr << "begin of cycle #" << sc_simulation_time() << "\n";
    90     }
    91 #endif
    92 
    93         func_simulate_1_cycle();
     96        std::cerr << "begin of cycle #" << sc_simulation_time () << "\n";
     97    }
     98#endif
     99
     100        func_simulate_1_cycle (); 
    94101
    95102        ++nb_cycles;
     
    97104#pragma omp master
    98105    {
    99         std::cerr << "end of cycle\n";
     106        std::cerr << "end of cycle\n";
    100107    }
    101108#endif
    102109}
    103110
    104 inline void internal_sc_cycle1(int number_of_cycles) { 
    105     extern unsigned long long busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml;
    106     extern unsigned long long last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml;
    107     extern unsigned int nb_func[2];
    108     extern unsigned int expected_globaltime;
    109     extern volatile unsigned int globaltime;
     111inline void
     112internal_sc_cycle1 (int number_of_cycles)
     113
     114
     115extern unsigned long long busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml;
     116extern unsigned long long last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml;
     117extern unsigned int nb_func[2];
    110118#ifdef _OPENMP
    111119#pragma omp threadprivate (busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml, nb_func)
    112120#pragma omp threadprivate (last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml)
     121#endif
     122extern unsigned int expected_globaltime;
     123extern volatile unsigned int globaltime;
     124#ifdef _OPENMP
    113125#pragma omp threadprivate (expected_globaltime)
    114126#pragma omp shared (globaltime)
    115127#endif
    116     extern unsigned int num_omp_threads;
     128
     129extern unsigned int num_omp_threads;
    117130
    118131
     
    120133#pragma omp parallel
    121134#endif
    122     {
    123         int cyclecount = number_of_cycles;
    124         busy_wait_f0 = busy_wait_f1 = busy_wait_up = busy_wait_ml = total_assig = 0;
    125         last_wait_f0 = last_wait_f1 = last_wait_up = last_wait_ml = 0;
    126 
    127         expected_globaltime = 0;
    128 #ifdef _OPENMP
    129 #pragma omp master
    130 #endif
    131         {
    132             globaltime = 0;
    133 #ifdef _OPENMP
    134             num_omp_threads = omp_get_num_threads();
     135  {
     136        int cyclecount = number_of_cycles;
     137        busy_wait_f0 = busy_wait_f1 = busy_wait_up = busy_wait_ml = total_assig = 0;
     138        last_wait_f0 = last_wait_f1 = last_wait_up = last_wait_ml = 0;
     139
     140        expected_globaltime = 0;
     141#ifdef _OPENMP
     142#pragma omp master
     143#endif
     144    {
     145        globaltime = 0;
     146#ifdef _OPENMP
     147  num_omp_threads = omp_get_num_threads();
    135148#else
    136             num_omp_threads = 1;
    137 #endif
    138         }
     149  num_omp_threads = 1;
     150#endif
     151    }
    139152
    140153#ifdef _OPENMP
    141154#pragma omp barrier
    142155#endif
    143         while (!(have_to_stop || cyclecount == 0)) {
    144         //while (!(have_to_stop || number_of_cycles == 0)) {
    145 #ifdef _OPENMP
    146 #pragma omp master
    147 #endif
    148             {
    149                 trace_all(false);
    150             }
    151             internal_sc_cycle2();
    152 #ifdef _OPENMP
    153 #pragma omp master
    154 #endif
    155             {
    156                 trace_all(true);
    157             }
    158             cyclecount = (number_of_cycles < 0) ? number_of_cycles : cyclecount - 1;
    159             // number_of_cycles = (number_of_cycles < 0) ? number_of_cycles : number_of_cycles - 1;
    160         }
     156        while (!((have_to_stop) | (cyclecount == 0))) {
     157#ifdef _OPENMP
     158#pragma omp master
     159#endif
     160            {
     161                trace_all  (false);
     162            }
     163                internal_sc_cycle2 ();
     164#ifdef _OPENMP
     165#pragma omp master
     166#endif
     167            {
     168                trace_all  (true);
     169            }
     170            cyclecount = (number_of_cycles<0)?number_of_cycles:cyclecount-1;
     171        }
    161172#ifdef _OPENMP
    162173#pragma omp barrier
    163 #endif
    164 #if 0
    165 #ifdef _OPENMP
    166174#pragma omp critical
    167         {
    168             std::cerr << "Thread " << omp_get_thread_num() << " busy_wait " <<
    169                 busy_wait_f0 << " " << busy_wait_up << " " <<
    170                 busy_wait_f1 << " " << busy_wait_ml << std::endl;
    171         }
     175    {
     176        std::cerr << "Thread " << omp_get_thread_num() << " busy_wait " <<
     177            busy_wait_f0 << " " << busy_wait_up << " " <<
     178            busy_wait_f1 << " " << busy_wait_ml << std::endl;
     179    }
    172180#pragma omp critical
    173         {
    174             std::cerr << "Thread " << omp_get_thread_num() << " last_wait " <<
    175                 last_wait_f0 << " " << last_wait_up << " " <<
    176                 last_wait_f1 << " " << last_wait_ml << std::endl;
    177         }
     181    {
     182        std::cerr << "Thread " << omp_get_thread_num() << " last_wait " <<
     183            last_wait_f0 << " " << last_wait_up << " " <<
     184            last_wait_f1 << " " << last_wait_ml << std::endl;
     185    }
    178186#pragma omp critical
    179         {
    180             std::cerr << "Thread " << omp_get_thread_num() << " nfuncs "
    181                 << nb_func[0] << " " << nb_func[1] << " total_assig " <<
    182                 total_assig << std::endl;
    183         }
    184 #endif
    185 #endif
    186     }
     187    {
     188        std::cerr << "Thread " << omp_get_thread_num() << " nfuncs "
     189          << nb_func[0] << " " << nb_func[1] << " total_assig " <<
     190           total_assig << std::endl;
     191    }
     192#endif // _OPENMP
     193  }
    187194}
    188195
     
    206213#ifdef _OPENMP
    207214#pragma omp parallel
    208 #endif
    209         update();
    210         func_combinationals();
    211     }
    212 
    213     internal_sc_cycle1((int) duration);
    214 
    215     // don't need to do func_combinationals since 'unstable' flag is now false
    216     if (is_posted_write()) {
     215#endif // _OPENMP
     216        update ();
     217    func_combinationals ();
     218  }
     219       
     220        internal_sc_cycle1 ((int)duration);
     221
     222  // don't need to do func_combinationals since 'unstable' flag is now false
     223  if (is_posted_write ()) {
    217224#ifdef _OPENMP
    218225#pragma omp parallel
    219 #endif
    220         update();
    221         func_combinationals();
    222     }
     226#endif // _OPENMP
     227      update ();
     228    func_combinationals ();
     229  }
    223230}
    224231
Note: See TracChangeset for help on using the changeset viewer.