9 #include <lib/topology.h> 14 #include <lib/jsmn_helper.h> 17 #include <datatypes/heap.h> 29 unsigned size_checkpoint_obstacles(
void){
32 sizeof(unsigned) * 2 * topology_global.
lp_cnt;
36 void *load_topology_file_obstacles(
c_jsmntok_t *root_token,
const char *json_base){
39 const unsigned lp_cnt = topology_global.
lp_cnt;
41 c_jsmntok_t *values_tok = get_value_token_by_key(root_token, json_base, root_token,
"values");
42 if(!values_tok|| values_tok->type != JSMN_ARRAY || children_count_token(root_token, values_tok) != lp_cnt)
43 rootsim_error(
true,
"Invalid or missing json value with key \"values\"");
49 for (i = 0; i < lp_cnt; ++i) {
50 if(parse_double_token(json_base, get_next_token(root_token, values_tok, &closure), &tmp) < 0)
51 rootsim_error(
true,
"Invalid value found in the \"value\" array");
53 if(tmp >= 1.0 && tmp <= 1.0) {
bitmap_set(ret_data, i);}
59 topology_t *topology_obstacles_init(
unsigned this_region_id,
void *topology_data){
61 const unsigned lp_cnt = topology_global.
lp_cnt;
79 lp_id = get_raw_receiver(this_region_id, i);
92 topology->
dirty =
true;
97 #define __cmp_dijkstra_h(a, b) (((a).hops > (b).hops) - ((b).hops > (a).hops)) 99 static void dijkstra_obstacles(
const topology_t *topology,
unsigned int source_cell,
unsigned int previous[RegionsCount()]) {
102 struct _dijkstra_h_t{
107 const unsigned directions = topology_global.
directions;
108 const unsigned lp_cnt = topology_global.
lp_cnt;
109 unsigned i, receiver;
110 unsigned min_costs[lp_cnt];
111 rootsim_heap(
struct _dijkstra_h_t) heap;
114 struct _dijkstra_h_t current_scan = {0, source_cell}, partial_scan = {0};
118 min_costs[i] = UINT_MAX;
119 previous[i] = UINT_MAX;
124 min_costs[source_cell] = current_scan.hops;
126 heap_insert(heap, current_scan, __cmp_dijkstra_h);
128 while(!heap_empty(heap)) {
130 current_scan = heap_extract(heap, __cmp_dijkstra_h);
132 if(current_scan.hops > min_costs[current_scan.cell])
135 partial_scan.hops = current_scan.hops + 1;
137 for(i = 0; i < directions; ++i){
139 receiver = get_raw_receiver(current_scan.cell, i);
144 if(partial_scan.hops < min_costs[receiver]){
146 previous[receiver] = current_scan.cell;
148 partial_scan.cell = receiver;
150 min_costs[receiver] = partial_scan.hops;
152 heap_insert(heap, partial_scan, __cmp_dijkstra_h);
157 #undef __cmp_dijsktra_h 159 static void refresh_cache_obstacles(
topology_t *topology){
161 const unsigned lp_cnt = topology_global.
lp_cnt;
166 memset(&topology->
prev_next_cache[lp_cnt], UCHAR_MAX,
sizeof(
unsigned) * lp_cnt);
167 topology->
dirty =
false;
171 unsigned int find_receiver_obstacles(
void) {
176 rootsim_error(
false,
"FindReceiver(): this is an obstacle region!!!\n");
183 const unsigned directions = topology_global.
directions;
184 const unsigned *neighbours;
195 receiver = neighbours[(unsigned)(directions *
Random())];
201 receiver = (directions + 1) *
Random();
209 receiver = ((topology_global.
lp_cnt - 1) *
Random()) + 1;
217 unsigned refresh_free = 0;
237 topology->
dirty =
true;
240 void set_value_topology_obstacles(
unsigned from,
unsigned to,
double value){
250 toggle_bit_and_state(topology, bitmap, from);
252 unsigned i = topology_global.
lp_cnt;
260 void update_topology_obstacles(
void){
262 toggle_bit_and_state(topology, topology->
data, *((
unsigned *)
current_evt->event_content));
265 double get_value_topology_obstacles(
unsigned from,
unsigned to){
270 bool is_reachable_obstacles(
unsigned to){
272 return find_receiver_toward_obstacles(to) != UINT_MAX;
275 unsigned int find_receiver_toward_obstacles(
unsigned int to){
277 const unsigned lp_cnt = topology_global.
lp_cnt;
280 refresh_cache_obstacles(topology);
284 if(*ret_p == UINT_MAX){
286 unsigned path[lp_cnt];
297 if(*ret_p == this_lp){
305 double compute_min_tour_obstacles(
unsigned int source,
unsigned int dest,
unsigned int result[RegionsCount()]) {
307 const unsigned lp_cnt = topology_global.
lp_cnt;
308 unsigned int previous[lp_cnt], hops;
311 refresh_cache_obstacles(topology);
312 if(!(hops = build_path(lp_cnt, result, topology->
prev_next_cache, source, dest))){
321 dijkstra_obstacles(topology, source, previous);
323 if(!(hops = build_path(lp_cnt, result, previous, source, dest)))
unsigned neighbours_id[6]
#define bitmap_set(bitmap, bit_index)
This sets the bit with index bit_index of the bitmap bitmap.
enum _topology_geometry_t geometry
A generic invalid direction.
ROOT-Sim header for model development.
#define bitmap_required_size(requested_bits)
Computes the required size of a bitmap with requested_bits entries.
unsigned int to_int
The GID numerical value.
The ROOT-Sim scheduler main module header.
#define bitmap_reset(bitmap, bit_index)
This resets the bit with index bit_index of the bitmap bitmap.
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
an arbitrary shaped topology
a ring shaped topology direction
GID_t gid
Global ID of the LP.
#define bitmap_check(bitmap, bit_index)
This checks if the bit with index bit_index of the bitmap bitmap is set or unset. ...
a ring shaped topology walkable in a single direction
unsigned * prev_next_cache
#define bitmap_initialize(memory_pointer, requested_bits)
This initializes the bitmap at memory_pointer containing requested_bits entries.
unsigned char rootsim_bitmap
This defines a generic bitmap.
#define unlikely(exp)
Optimize the branch as likely not taken.
the customised struct for TOPOLOGY_OBSTACLES representation