void cndfs_shared_init (run_t *run) { HREassert (GRED.g == 0); HREassert (GGREEN.g == 1); HREassert (GDANGEROUS.g == 2); set_alg_local_init (run->alg, cndfs_local_init); set_alg_global_init (run->alg, cndfs_global_init); set_alg_global_deinit (run->alg, cndfs_global_deinit); set_alg_local_deinit (run->alg, cndfs_local_deinit); set_alg_print_stats (run->alg, cndfs_print_stats); set_alg_run (run->alg, endfs_blue); set_alg_state_seen (run->alg, cndfs_state_seen); set_alg_reduce (run->alg, cndfs_reduce); if (run->shared != NULL) return; run->shared = RTmallocZero (sizeof(alg_shared_t)); run->shared->color_bit_shift = 0; run->shared->top_level = run; run->shared->run_is_stopped = run_get_is_stopped (run); run->shared->run_stop = run_get_stop (run); run_set_is_stopped (run, cndfs_is_stopped); run_set_stop (run, cndfs_stop); int i = 1; run_t *previous = run; run_t *next = NULL; while (strategy[i] != Strat_None) { next = run_create (false); next->shared = RTmallocZero (sizeof(alg_shared_t)); next->shared->previous = previous; next->shared->top_level = run; next->shared->rec = NULL; run_set_is_stopped (next, cndfs_is_stopped); run_set_stop (next, cndfs_stop); next->shared->color_bit_shift = previous->shared->color_bit_shift + num_global_bits (strategy[i]); alg_shared_init_strategy (next, strategy[i]); previous->shared->rec = next; previous = next; i++; } }
void ndfs_reduce (run_t *run, wctx_t *ctx) { if (run->reduced == NULL) { run->reduced = RTmallocZero (sizeof (alg_reduced_t)); } alg_reduced_t *reduced = run->reduced; counter_t *blue = &ctx->local->counters; counter_t *red = &ctx->local->red; work_counter_t *blue_work = ctx->counters; work_counter_t *red_work = &ctx->local->red_work; add_results (&reduced->blue, blue); add_results (&reduced->red, red); work_add_results (&reduced->red_work, red_work); // publish local memory statistics for run class run->total.local_states += blue_work->level_max + red_work->level_max; if (W >= 4 || !log_active(infoLong)) return; // print some local info float runtime = RTrealTime(ctx->timer); Warning (info, "Nested depth-first search worker ran %.3f sec", runtime); work_report ("[Blue]", blue_work); work_report ("[Red ]", red_work); }
void cndfs_reduce (run_t *run, wctx_t *ctx) { if (run->reduced == NULL) { run->reduced = RTmallocZero (sizeof (cndfs_reduced_t)); cndfs_reduced_t *reduced = (cndfs_reduced_t *) run->reduced; reduced->waittime = 0; } cndfs_reduced_t *reduced = (cndfs_reduced_t *) run->reduced; cndfs_alg_local_t *cloc = (cndfs_alg_local_t *) ctx->local; float waittime = RTrealTime(cloc->timer); reduced->waittime += waittime; reduced->rec += cloc->counters.rec; reduced->max_load += fset_max_load (cloc->pink); ndfs_reduce (run, ctx); if (log_active(infoLong)) { fset_print_statistics (cloc->pink, "Pink stack set:"); } if (run->shared->rec != NULL) { alg_global_t *sm = ctx->global; alg_reduce (run->shared->rec, sm->rec); } }
void tarjan_local_init (run_t *run, wctx_t *ctx) { ctx->local = RTmallocZero (sizeof (alg_local_t)); ctx->local->target = state_info_create (); // extend state_info with tarjan_state information state_info_add_simple (ctx->local->target, sizeof (uint32_t), &ctx->local->target_tarjan.index); state_info_add_simple (ctx->local->target, sizeof (uint32_t), &ctx->local->target_tarjan.lowlink); state_info_add_simple (ctx->state, sizeof (uint32_t), &ctx->local->state_tarjan.index); state_info_add_simple (ctx->state, sizeof (uint32_t), &ctx->local->state_tarjan.lowlink); size_t len = state_info_serialize_int_size (ctx->state); ctx->local->search_stack = dfs_stack_create (len); ctx->local->tarjan_stack = dfs_stack_create (len); ctx->local->cnt.scc_count = 0; ctx->local->cnt.tarjan_counter = 0; ctx->local->visited_states = fset_create (sizeof (ref_t), sizeof (raw_data_t), 10, dbs_size); #ifdef SEARCH_COMPLETE_GRAPH // provide the input file name to dlopen_setup dlopen_setup (files[0]); #endif (void) run; }
void cndfs_global_init (run_t *run, wctx_t *ctx) { ctx->global = RTmallocZero (sizeof(alg_global_t)); ctx->global->work = SIZE_MAX; (void) run; }
void cndfs_local_init (run_t *run, wctx_t *ctx) { alg_local_t *loc = RTmallocZero (sizeof(cndfs_alg_local_t)); ctx->local = loc; cndfs_local_setup (run, ctx); }
void timed_local_init (run_t *run, wctx_t *ctx) { ta_alg_local_t *loc = RTmallocZero (sizeof(ta_alg_local_t)); ctx->local = (alg_local_t *) loc; reach_local_setup (run, ctx); statistics_init (&loc->counters.lattice_ratio); }
static stream_t stream_zip(stream_t parent,int compress,int level,int bufsize){ stream_t s=(stream_t)RTmallocZero(sizeof(struct stream_s)); stream_init(s); s->bufsize=bufsize; s->s=parent; s->compress=compress; if(stream_writable(parent)){ s->procs.write=gzip_write; //s->procs.flush= TO DO s->wr.zalloc = Z_NULL; s->wr.zfree = Z_NULL; s->wr.opaque = Z_NULL; s->wr_buf=(char*)RTmalloc(bufsize); s->wr.next_in=Z_NULL; s->wr.avail_in=0; s->wr.next_out=s->wr_buf; s->wr.avail_out=bufsize; if (compress) { if (deflateInit(&s->wr, level)!= Z_OK) { Abort("gzip init failed"); } } else { if (inflateInit(&s->wr)!= Z_OK) { Abort("gzip init failed"); } } } else { s->wr_buf=NULL; } if(stream_readable(parent)){ s->procs.read_max=gzip_read_max; s->procs.read=gzip_read; //s->procs.empty= TO DO s->rd.zalloc = Z_NULL; s->rd.zfree = Z_NULL; s->rd.opaque = Z_NULL; s->rd.next_in=Z_NULL; s->rd.avail_in=0; s->rd.next_out=Z_NULL; s->rd.avail_out=0; s->rd_buf=(char*)RTmalloc(bufsize); if (compress) { if (inflateInit(&s->rd)!= Z_OK) { Abort("gzip init failed"); } } else { if (deflateInit(&s->rd, level)!= Z_OK) { Abort("gzip init failed"); } } } else { s->rd_buf=NULL; } s->procs.close=gzip_close; s->procs.close_z=gzip_close_z; return stream_buffer(s,4096); }
void tarjan_reduce (run_t *run, wctx_t *ctx) { if (run->reduced == NULL) { run->reduced = RTmallocZero (sizeof (counter_t)); } counter_t *reduced = (counter_t *) run->reduced; counter_t *cnt = &ctx->local->cnt; reduced->scc_count += cnt->scc_count; }
void timed_reduce (run_t *run, wctx_t *ctx) { if (run->reduced == NULL) { run->reduced = RTmallocZero (sizeof (ta_reduced_t) + CACHE_LINE_SIZE); } ta_reduced_t *reduced = (ta_reduced_t *) run->reduced; ta_alg_local_t *ta_loc = (ta_alg_local_t *) ctx->local; ta_add_results (&reduced->counters, &ta_loc->counters); reach_reduce (run, ctx); }
void timed_global_init (run_t *run, wctx_t *ctx) { if (PINS_POR) Abort ("POR not compatible with timed automata"); ctx->global = RTmallocZero (sizeof(ta_alg_global_t)); ta_alg_global_t *sm = (ta_alg_global_t *) ctx->global; // Extend state info with a lattice location state_info_add_simple (ctx->state, sizeof(lm_loc_t), &sm->lloc); state_info_add_simple (ctx->initial, sizeof(lm_loc_t), &sm->lloc); state_info_t *si_perm = permute_state_info(ctx->permute); state_info_add_simple (si_perm, sizeof(lm_loc_t), &sm->lloc); reach_global_setup (run, ctx); }
void timed_shared_init (run_t *run) { set_alg_local_init (run->alg, timed_local_init); set_alg_global_init (run->alg, timed_global_init); set_alg_global_deinit (run->alg, timed_destroy); set_alg_local_deinit (run->alg, timed_destroy_local); set_alg_print_stats (run->alg, timed_print_stats); set_alg_run (run->alg, timed_run); set_alg_reduce (run->alg, timed_reduce); run->shared = RTmallocZero (sizeof (ta_alg_shared_t)); reach_init_shared (run); ta_alg_shared_t *shared = (ta_alg_shared_t *) run->shared; shared->lmap = state_store_lmap (global->store); }
lts_file_t lts_writer(lts_t lts,int segments,lts_file_t settings){ lts_file_t file=lts_file_bare("<heap>",lts->ltstype,segments,settings,sizeof(struct lts_file_s)); file->lts=lts; file->segments=segments; file->state_perseg=(uint32_t*)RTmallocZero(segments*sizeof(uint32_t)); file->edge_labels=lts_type_get_edge_label_count(lts->ltstype); lts_file_set_write_init(file,write_init); lts_file_set_write_state(file,write_state); lts_file_set_write_edge(file,write_edge); lts_file_set_close(file,write_close); lts_file_complete(file); lts_set_type(file->lts,LTS_LIST); int T=lts_type_get_type_count(lts->ltstype); for(int i=0;i<T;i++){ lts_file_set_table(file,i,lts->values[i]); } return file; }
string_index_t SIcreate(){ int i; string_index_t si; si=(string_index_t)RTmallocZero(sizeof(struct stringindex)); si->count=0; si->free_list=END_OF_LIST; si->man=create_manager(DATA_BLOCK_SIZE); //si->next=(int*)RTmalloc(DATA_BLOCK_SIZE*sizeof(int)); ADD_ARRAY_CB(si->man,si->next,int,next_resize,NULL); //si->len=(int*)RTmalloc(DATA_BLOCK_SIZE*sizeof(int)); ADD_ARRAY_CB(si->man,si->len,int,len_resize,si); //si->data=(char**)RTmalloc(DATA_BLOCK_SIZE*sizeof(char*)); ADD_ARRAY(si->man,si->data,char*); //create_free_list(si); si->table=(int*)RTmalloc((TABLE_INITIAL+1)*sizeof(int)); si->mask=TABLE_INITIAL; for(i=0;i<=TABLE_INITIAL;i++){ si->table[i]=END_OF_LIST; } return si; };
/* * Sanitizes and caches all type symbols of an etf_model_t. Should only be * called once. */ void sanitize_types(etf_model_t model) { lts_type_t ltstype = etf_type(model); int n_types = lts_type_get_type_count(ltstype); sanitized_types = (char***)RTmallocZero(n_types*sizeof(char**)); for (int i=0;i<n_types;i++) { int v_count = etf_get_value_count(model, i); if (v_count) { sanitized_types[i] = (char**)RTmalloc(v_count*sizeof(char*)); for (int j=0;j<v_count;j++) { chunk ch = etf_get_value(model, i, j); char tmp[ch.len+1]; strncpy(tmp,ch.data,ch.len); tmp[ch.len] = '\0'; int len = ch.len+2; sanitized_types[i][j] = (char*)RTmalloc(len); sanitize_ID(tmp,len,sanitized_types[i][j]); Debug("Sanitizing type %s to %s", tmp, sanitized_types[i][j]); } } } }
ci_list * ci_create (size_t size) { return RTmallocZero (sizeof(int[size + 1])); }
void DVE2loadGreyboxModel(model_t model, const char *filename) { lts_type_t ltstype; matrix_t *dm_info = RTmalloc(sizeof(matrix_t)); matrix_t *dm_read_info = RTmalloc(sizeof(matrix_t)); matrix_t *dm_actions_read_info = RTmalloc(sizeof(matrix_t)); matrix_t *dm_may_write_info = RTmalloc(sizeof(matrix_t)); matrix_t *dm_must_write_info = RTmalloc(sizeof(matrix_t)); matrix_t *sl_info = RTmalloc(sizeof(matrix_t)); //assume sequential use: if (NULL == dlHandle) { char *extension = strrchr (filename, '.'); HREassert (extension != NULL, "No filename extension %s", filename); ++extension; if (0==strcmp (extension, "dve2C") || 0==strcmp (extension, "so")) { DVE2loadDynamicLib(model, filename); } else { DVE2compileGreyboxModel(model, filename); } } gb_context_t ctx=(gb_context_t)RTmalloc(sizeof(struct grey_box_context)); GBsetContext(model,ctx); // get ltstypes int state_length = get_state_variable_count(); ltstype=lts_type_create(); // adding types int ntypes = get_state_variable_type_count(); for(int i = 0; i < ntypes; i++) { const char* type_name = get_state_variable_type_name(i); HREassert (type_name != NULL, "invalid type name"); if (lts_type_add_type(ltstype, type_name, NULL) != i) { Abort("wrong type number"); } int type_value_count = get_state_variable_type_value_count(i); if (0 == type_value_count) { lts_type_set_format (ltstype, i, LTStypeDirect); } else { lts_type_set_format (ltstype, i, LTStypeEnum); } } int guard_type = lts_type_add_type (ltstype, "guard", NULL); lts_type_set_format (ltstype, guard_type, LTStypeTrilean); lts_type_set_state_length(ltstype, state_length); // set state name & type for(int i=0; i < state_length; ++i) { const char* name = get_state_variable_name(i); const int type = get_state_variable_type(i); lts_type_set_state_name(ltstype,i,name); lts_type_set_state_typeno(ltstype,i,type); } // compute state label names int nguards = get_guard_count(); // TODO: should be in model has guards block..? int sl_size = 0 + nguards + (have_property() ? 1 : 0); // assumption on state labels: // state labels (idx): 0 - nguards-1 = guard state labels // state label (idx): nguards = property state label lts_type_set_state_label_count (ltstype, sl_size); char buf[256]; for(int i=0; i < nguards; i++) { snprintf(buf, 256, "%s_%d", LTSMIN_LABEL_TYPE_GUARD_PREFIX, i); lts_type_set_state_label_name (ltstype, i, buf); lts_type_set_state_label_typeno (ltstype, i, guard_type); } if (have_property()) { lts_type_set_state_label_name (ltstype, nguards, LTSMIN_STATE_LABEL_ACCEPTING); lts_type_set_state_label_typeno (ltstype, nguards, guard_type); ctx->accepting_state_label_idx = nguards; } else { ctx->accepting_state_label_idx = -1; } GBsetLTStype(model, ltstype); // setting values for types for(int i=0; i < ntypes; i++) { int type_value_count = get_state_variable_type_value_count(i); if (lts_type_get_format(ltstype, i) != LTStypeChunk && lts_type_get_format(ltstype, i) != LTStypeEnum) { Debug ("Skipping type values for non-chunk type %s", lts_type_get_type(ltstype, i)); continue; } for(int j=0; j < type_value_count; ++j) { const char* type_value = get_state_variable_type_value(i, j); pins_chunk_put_at (model, i, chunk_str((char*)type_value), j); } } lts_type_validate(ltstype); int ngroups = get_transition_count(); dm_create(dm_info, ngroups, state_length); dm_create(dm_read_info, ngroups, state_length); dm_create(dm_actions_read_info, ngroups, state_length); dm_create(dm_may_write_info, ngroups, state_length); dm_create(dm_must_write_info, ngroups, state_length); for(int i=0; i < dm_nrows(dm_info); i++) { int* proj = (int*)get_transition_read_dependencies(i); for(int j=0; j<state_length; j++) { if (proj[j]) { dm_set(dm_info, i, j); dm_set(dm_read_info, i, j); } } proj = (int*)get_transition_actions_read_dependencies(i); for(int j=0; j<state_length; j++) { if (proj[j]) { dm_set(dm_actions_read_info, i, j); } } proj = (int*)get_transition_may_write_dependencies(i); for(int j=0; j<state_length; j++) { if (proj[j]) { dm_set(dm_info, i, j); dm_set(dm_may_write_info, i, j); } } proj = (int*)get_transition_must_write_dependencies(i); for(int j=0; j<state_length; j++) { if (proj[j]) { dm_set(dm_must_write_info, i, j); } } } GBsetDMInfo(model, dm_info); GBsetDMInfoRead(model, dm_read_info); GBsetMatrix(model, LTSMIN_MATRIX_ACTIONS_READS, dm_actions_read_info, PINS_MAY_SET, PINS_INDEX_GROUP, PINS_INDEX_STATE_VECTOR); GBsetDMInfoMayWrite(model, dm_may_write_info); GBsetDMInfoMustWrite(model, dm_must_write_info); // set state label matrix (accepting label and guards) get_label_method_t sl_long = NULL; get_label_all_method_t sl_all = NULL; dm_create(sl_info, sl_size, state_length); // if the model exports a property, reserve first for accepting label if (have_property()) { for (int i=0; i<state_length; ++i) { if (strcmp ("LTL_property", lts_type_get_state_name(ltstype, i)) == 0) { dm_set(sl_info, ctx->accepting_state_label_idx, i); } } } // if the model has guards, add guards as state labels if (have_property()) { // filter the property sl_long = sl_long_p_g; sl_all = sl_all_p_g; } else { // pass request directly to dynamic lib sl_long = (get_label_method_t) get_guard; sl_all = (get_label_all_method_t) get_guard_all; } // set the guards per transition group GBsetGuardsInfo(model, (guard_t**) get_all_guards()); // initialize state label matrix // assumption, guards come first (0-nguards) for(int i=0; i < nguards; i++) { int* guards = (int*)get_guard_matrix(i); for(int j=0; j<state_length; j++) { if (guards[j]) dm_set(sl_info, i, j); } } // set guard may be co-enabled relation if (get_guard_may_be_coenabled_matrix) { matrix_t *gce_info = RTmalloc(sizeof(matrix_t)); dm_create(gce_info, nguards, nguards); for(int i=0; i < nguards; i++) { int* guardce = (int*)get_guard_may_be_coenabled_matrix(i); for(int j=0; j<nguards; j++) { if (guardce[j]) dm_set(gce_info, i, j); } } GBsetGuardCoEnabledInfo(model, gce_info); } // set guard necessary enabling set info if (get_guard_nes_matrix) { matrix_t *gnes_info = RTmalloc(sizeof(matrix_t)); dm_create(gnes_info, nguards, ngroups); for(int i=0; i < nguards; i++) { int* guardnes = (int*)get_guard_nes_matrix(i); for(int j=0; j<ngroups; j++) { if (guardnes[j]) dm_set(gnes_info, i, j); } } GBsetGuardNESInfo(model, gnes_info); } // set guard necessary disabling set info if (get_guard_nds_matrix) { matrix_t *gnds_info = RTmalloc(sizeof(matrix_t)); dm_create(gnds_info, nguards, ngroups); for(int i=0; i < nguards; i++) { int* guardnds = (int*)get_guard_nds_matrix(i); for(int j=0; j<ngroups; j++) { if (guardnds[j]) dm_set(gnds_info, i, j); } } GBsetGuardNDSInfo(model, gnds_info); } if (!get_dna_matrix) { Warning (info, "*** Warning ***"); Warning (info, "You are using an old version of our patched DiVinE compiler."); Warning (info, "This might influence the performance of partial order reduction negatively."); Warning (info, "Please download the latest from: http://fmt.cs.utwente.nl/tools/ltsmin/"); Warning (info, "*** Warning ***"); } else { matrix_t *dna_info = RTmalloc(sizeof(matrix_t)); dm_create(dna_info, ngroups, ngroups); for(int i=0; i < ngroups; i++) { int* dna = (int*)get_dna_matrix(i); for(int j=0; j<ngroups; j++) { if (dna[j]) dm_set(dna_info, i, j); } } GBsetDoNotAccordInfo(model, dna_info); } // set the group implementation sl_group_t* sl_group_all = RTmallocZero(sizeof(sl_group_t) + sl_size * sizeof(int)); sl_group_all->count = sl_size; for(int i=0; i < sl_group_all->count; i++) sl_group_all->sl_idx[i] = i; sl_group_t* sl_group_guards = RTmallocZero(sizeof(sl_group_t) + nguards * sizeof(int)); sl_group_guards->count = nguards; for(int i=0; i < sl_group_guards->count; i++) sl_group_guards->sl_idx[i] = i; GBsetStateLabelGroupInfo(model, GB_SL_ALL, sl_group_all); GBsetStateLabelGroupInfo(model, GB_SL_GUARDS, sl_group_guards); GBsetStateLabelsGroup(model, sl_group); GBsetStateLabelInfo(model, sl_info); if (sl_long != NULL) GBsetStateLabelLong(model, sl_long); if (sl_all != NULL) GBsetStateLabelsAll(model, sl_all); // get initial state int state[state_length]; get_initial_state((char*)state); GBsetInitialState(model,state); GBsetNextStateAll (model, (next_method_black_t) get_successors); GBsetNextStateLong (model, (next_method_grey_t) get_successor); GBsetActionsLong (model, (next_method_grey_t) get_action); }
void ndfs_local_init (run_t *run, wctx_t *ctx) { ctx->local = RTmallocZero (sizeof(alg_local_t)); ndfs_local_setup (run, ctx); }