LCOV - code coverage report
Current view: top level - core/src/lp - lp.c Hit Total Coverage
Test: ROOT-Sim master Documentation Coverage Lines: 2 14 14.3 %
Date: 2021-03-25 15:11:55

          Line data    Source code
       1           1 : /**
       2             :  * @file lp/lp.c
       3             :  *
       4             :  * @brief LP construction functions
       5             :  *
       6             :  * LP construction functions
       7             :  *
       8             :  * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
       9             :  * SPDX-License-Identifier: GPL-3.0-only
      10             :  */
      11             : #include <lp/lp.h>
      12             : 
      13             : #include <core/sync.h>
      14             : #include <gvt/fossil.h>
      15             : 
      16           0 : uint64_t lid_node_first;
      17           0 : __thread uint64_t lid_thread_first;
      18           0 : __thread uint64_t lid_thread_end;
      19             : 
      20           0 : __thread struct lp_ctx *current_lp;
      21           0 : struct lp_ctx *lps;
      22           1 : lp_id_t n_lps_node;
      23             : 
      24           0 : #define lp_partition_start(part_id, part_fnc, lp_tot, part_cnt, offset) \
      25             : __extension__({                                                         \
      26             :         lp_id_t _g = (part_id) * (lp_tot) / (part_cnt) + offset;        \
      27             :         while (_g > offset && part_fnc(_g) >= (part_id))          \
      28             :                 --_g;                                                   \
      29             :         while (part_fnc(_g) < (part_id))                             \
      30             :                 ++_g;                                                   \
      31             :         _g;                                                             \
      32             : })
      33             : 
      34           0 : void lp_global_init(void)
      35             : {
      36             :         lid_node_first = lp_partition_start(nid, lid_to_nid, n_lps, n_nodes, 0);
      37             :         n_lps_node = lp_partition_start(nid + 1, lid_to_nid, n_lps, n_nodes, 0)
      38             :                         - lid_node_first;
      39             : 
      40             :         lps = mm_alloc(sizeof(*lps) * n_lps_node);
      41             :         lps -= lid_node_first;
      42             : 
      43             :         if (n_lps_node < n_threads) {
      44             :                 log_log(LOG_WARN, "The simulation will run with %u threads instead of the available %u",
      45             :                                 n_lps_node, n_threads);
      46             :                 n_threads = n_lps_node;
      47             :         }
      48             : }
      49             : 
      50           0 : void lp_global_fini(void)
      51             : {
      52             :         lps += lid_node_first;
      53             :         mm_free(lps);
      54             : }
      55             : 
      56           0 : void lp_init(void)
      57             : {
      58             :         lid_thread_first = lp_partition_start(rid, lid_to_rid, n_lps_node,
      59             :                         n_threads, lid_node_first);
      60             :         lid_thread_end = lp_partition_start(rid + 1, lid_to_rid, n_lps_node,
      61             :                         n_threads, lid_node_first);
      62             : 
      63             :         for (uint64_t i = lid_thread_first; i < lid_thread_end; ++i) {
      64             :                 current_lp = &lps[i];
      65             : 
      66             :                 model_allocator_lp_init();
      67             :                 current_lp->lib_ctx_p = malloc_mt(sizeof(*current_lp->lib_ctx_p));
      68             :                 lib_lp_init_pr();
      69             :                 process_lp_init();
      70             :                 termination_lp_init();
      71             :         }
      72             : }
      73             : 
      74           0 : void lp_fini(void)
      75             : {
      76             :         if (sync_thread_barrier()) {
      77             :                 for (uint64_t i = 0; i < n_lps_node ; ++i) {
      78             :                         current_lp = &lps[i + lid_node_first];
      79             :                         process_lp_deinit();
      80             :                 }
      81             :         }
      82             : 
      83             :         sync_thread_barrier();
      84             : 
      85             :         for (uint64_t i = lid_thread_first; i < lid_thread_end; ++i) {
      86             :                 current_lp = &lps[i];
      87             : 
      88             :                 process_lp_fini();
      89             :                 lib_lp_fini_pr();
      90             :                 model_allocator_lp_fini();
      91             :         }
      92             : 
      93             :         current_lp = NULL;
      94             : }
      95             : 
      96           0 : lp_id_t lp_id_get_mt(void)
      97             : {
      98             :         return current_lp - lps;
      99             : }
     100             : 
     101           0 : struct lib_ctx *lib_ctx_get_mt(void)
     102             : {
     103             :         return current_lp->lib_ctx_p;
     104             : }

Generated by: LCOV version 1.14