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 : __thread uint64_t lp_id_first; 17 0 : __thread uint64_t lp_id_end; 18 : 19 0 : __thread struct lp_ctx *current_lp; 20 0 : struct lp_ctx *lps; 21 1 : lp_id_t n_lps_node; 22 : 23 0 : #define lp_start_id_compute(trd) \ 24 : __extension__({ \ 25 : lp_id_t _g = (trd) * n_lps_node / n_threads; \ 26 : while (_g && lid_to_rid(_g) >= (trd)) \ 27 : --_g; \ 28 : while (lid_to_rid(_g) < (trd)) \ 29 : ++_g; \ 30 : _g; \ 31 : }) 32 : 33 0 : static void lp_iterator_init(void) 34 : { 35 : lp_id_first = lp_start_id_compute(rid); 36 : lp_id_end = lp_start_id_compute(rid + 1); 37 : } 38 : 39 0 : void lp_global_init(void) 40 : { 41 : uint64_t lps_offset = nid * n_lps / n_nodes; 42 : n_lps_node = ((nid + 1) * n_lps) / n_nodes - lps_offset; 43 : 44 : lps = mm_alloc(sizeof(*lps) * n_lps_node); 45 : lps -= lps_offset; 46 : 47 : if (n_lps_node < n_threads) { 48 : log_log( 49 : LOG_WARN, 50 : "The simulation will run with %u threads instead of the available %u", 51 : n_lps_node, 52 : n_threads 53 : ); 54 : n_threads = n_lps_node; 55 : } 56 : } 57 : 58 0 : void lp_global_fini(void) 59 : { 60 : uint64_t lps_offset = nid * n_lps / n_nodes; 61 : lps += lps_offset; 62 : 63 : mm_free(lps); 64 : } 65 : 66 0 : void lp_init(void) 67 : { 68 : lp_iterator_init(); 69 : 70 : for (uint64_t i = lp_id_first; i < lp_id_end; ++i) { 71 : current_lp = &lps[i]; 72 : 73 : model_allocator_lp_init(); 74 : current_lp->lib_ctx_p = malloc_mt(sizeof(*current_lp->lib_ctx_p)); 75 : lib_lp_init_pr(); 76 : process_lp_init(); 77 : termination_lp_init(); 78 : } 79 : } 80 : 81 0 : void lp_fini(void) 82 : { 83 : if (sync_thread_barrier()) { 84 : uint64_t lps_offset = nid * n_lps / n_nodes; 85 : for (uint64_t i = 0; i < n_lps_node ; ++i) { 86 : current_lp = &lps[i + lps_offset]; 87 : process_lp_deinit(); 88 : } 89 : } 90 : 91 : sync_thread_barrier(); 92 : 93 : for (uint64_t i = lp_id_first; i < lp_id_end; ++i) { 94 : current_lp = &lps[i]; 95 : 96 : process_lp_fini(); 97 : lib_lp_fini_pr(); 98 : model_allocator_lp_fini(); 99 : } 100 : 101 : current_lp = NULL; 102 : } 103 : 104 0 : lp_id_t lp_id_get_mt(void) 105 : { 106 : return current_lp - lps; 107 : } 108 : 109 0 : struct lib_ctx *lib_ctx_get_mt(void) 110 : { 111 : return current_lp->lib_ctx_p; 112 : }