16 #include <lib/topology.h> 29 unsigned size_checkpoint_probabilities(
void){
31 sizeof(
double) * (topology_global.
directions + 1) +
35 void *load_topology_file_probabilities(
c_jsmntok_t *root_token,
const char *json_base){
38 const unsigned lp_cnt = topology_global.
lp_cnt;
41 const unsigned exit_regions = topology_global.
directions + 1;
44 c_jsmntok_t *values_tok = get_value_token_by_key(root_token, json_base, root_token,
"values");
45 if(!values_tok|| values_tok->type != JSMN_ARRAY || children_count_token(root_token, values_tok) != lp_cnt)
46 rootsim_error(
true,
"Invalid or missing json value with key \"values\"");
49 double *ret_data = rsalloc(
sizeof(
double) * exit_regions * lp_cnt);
52 for(i = 0; i < lp_cnt; ++i){
53 aux_tok = get_at_token(root_token, values_tok, i);
56 if(!aux_tok || parse_double_array(root_token, json_base, aux_tok, exit_regions, &ret_data[i * exit_regions]) < 0)
57 rootsim_error(
true,
"Invalid or missing value in the array of probabilities for this region");
61 for (i = 0; i < exit_regions * lp_cnt; ++i) {
63 rootsim_error(
true,
"Found a negative probability weight in the topology file!");
69 topology_t *topology_probabilities_init(
unsigned this_region_id,
void *topology_data){
71 const unsigned exit_regions = topology_global.
directions + 1;
77 memcpy(topology->
data, ((
char *) topology_data) + this_region_id * exit_regions,
sizeof(
double) * exit_regions);
80 topology->
data[0] = 0.0;
81 for(i = 1; i < exit_regions; ++i)
82 topology->
data[i] = 1.0;
88 topology->
neighbours_id[i] = get_raw_receiver(this_region_id, i);
91 topology->
dirty =
true;
96 static void refresh_cache_probabilities(
topology_t *topology){
99 const unsigned exit_regions = topology_global.
directions + 1;
101 topology->
dirty =
false;
110 void set_value_topology_probabilities(
unsigned from,
unsigned to,
double value) {
113 topology->
data[to] = value;
114 topology->
dirty =
true;
121 bool is_reachable_probabilities(
unsigned to){
131 if(topology->
data[i] > 0)
139 rootsim_error(
true,
"Topology ring still not supported!");
143 return topology->
data[i] > 0;
146 rootsim_error(
true,
"This shouldn't happen, report to maintainer");
153 void update_topology_probabilities(
void){
156 if(topology->
data[upd_p->loc_i] > upd_p->val || topology->
data[upd_p->loc_i] < upd_p->val){
157 topology->
data[upd_p->loc_i] = upd_p->val;
158 topology->
dirty =
true;
162 double get_value_topology_probabilities(
unsigned from,
unsigned to) {
168 rootsim_error(
true,
"getting a remote probability value is still not supported... !");
179 #define select_direction() \ 181 direction = exit_regions * Random();\ 182 }while(Random() * sum >= topology->data[direction]);\ 187 unsigned int find_receiver_probabilities(
void) {
193 refresh_cache_probabilities(topology);
196 const unsigned exit_regions = topology_global.
directions + 1;
198 sum = topology->
data[exit_regions];
227 direction = exit_regions *
Random();
228 }
while (
Random() * sum >= topology->
data[direction]);
231 receiver = direction;
238 receiver = direction;
245 rootsim_error(
true,
"Wrong topology code specified: %d. Aborting...\n", topology);
251 #undef select_direction unsigned neighbours_id[6]
enum _topology_geometry_t geometry
A generic invalid direction.
ROOT-Sim header for model development.
unsigned int to_int
The GID numerical value.
The ROOT-Sim scheduler main module header.
a torus shaped grid topology (a wrapping around square topology)
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
double data[]
a pointer to the cache used to speedup queries on paths (unused in probabilities topology type) ...
__thread msg_t * current_evt
topology_t * topology
pointer to the topology struct
union _double_bits_trick upd
where to put the new value
an arbitrary shaped topology
a ring shaped topology direction
GID_t gid
Global ID of the LP.
double NeumaierSum(unsigned cnt, double addendums[cnt])
a ring shaped topology walkable in a single direction
the customised struct for TOPOLOGY_OBSTACLES representation