Esempio n. 1
0
void Yap_init_global(int max_table_size, int n_workers, int sch_loop, int delay_load) {
    int i;

    /* global data related to memory management */
#ifdef LIMIT_TABLING
    if (max_table_size)
        GLOBAL_MAX_PAGES = ((max_table_size - 1) * 1024 * 1024 / SHMMAX + 1) * SHMMAX / Yap_page_size;
    else
        GLOBAL_MAX_PAGES = -1;
#endif /* LIMIT_TABLING */
    INIT_PAGES(GLOBAL_PAGES_void, void *);
#ifdef YAPOR
    INIT_PAGES(GLOBAL_PAGES_or_fr, struct or_frame);
    INIT_PAGES(GLOBAL_PAGES_qg_sol_fr, struct query_goal_solution_frame);
    INIT_PAGES(GLOBAL_PAGES_qg_ans_fr, struct query_goal_answer_frame);
#endif /* YAPOR */
#ifdef TABLING_INNER_CUTS
    INIT_PAGES(GLOBAL_PAGES_tg_sol_fr, struct table_subgoal_solution_frame);
    INIT_PAGES(GLOBAL_PAGES_tg_ans_fr, struct table_subgoal_answer_frame);
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
#ifdef GLOBAL_TRIE
    INIT_PAGES(GLOBAL_PAGES_gt_node, struct global_trie_node);
    INIT_PAGES(GLOBAL_PAGES_gt_hash, struct global_trie_hash);
#endif /* GLOBAL_TRIE */
    INIT_PAGES(GLOBAL_PAGES_tab_ent, struct table_entry);
    INIT_PAGES(GLOBAL_PAGES_sg_fr, struct subgoal_frame);
    INIT_PAGES(GLOBAL_PAGES_sg_node, struct subgoal_trie_node);
    INIT_PAGES(GLOBAL_PAGES_ans_node, struct answer_trie_node);
    INIT_PAGES(GLOBAL_PAGES_sg_hash, struct subgoal_trie_hash);
    INIT_PAGES(GLOBAL_PAGES_ans_hash, struct answer_trie_hash);
    INIT_PAGES(GLOBAL_PAGES_dep_fr, struct dependency_frame);
#endif /* TABLING */
#if defined(YAPOR) && defined(TABLING)
    INIT_PAGES(GLOBAL_PAGES_susp_fr, struct suspension_frame);
#endif /* YAPOR && TABLING */

#ifdef YAPOR
    /* global static data */
    number_workers = n_workers;
    worker_pid(0) = getpid();
    for (i = 1; i < number_workers; i++) worker_pid(i) = 0;
    SCHEDULER_LOOP = sch_loop;
    DELAYED_RELEASE_LOAD = delay_load;

    /* global data related to or-performance */
    GLOBAL_number_goals = 0;
    GLOBAL_best_times(0) = 0;
    GLOBAL_performance_mode = PERFORMANCE_OFF;

    /* global data related to or-parallelism */
    BITMAP_clear(GLOBAL_bm_present_workers);
    for (i = 0; i < number_workers; i++)
        BITMAP_insert(GLOBAL_bm_present_workers, i);
    BITMAP_copy(GLOBAL_bm_idle_workers, GLOBAL_bm_present_workers);
    BITMAP_clear(GLOBAL_bm_root_cp_workers);
    BITMAP_clear(GLOBAL_bm_invisible_workers);
    BITMAP_clear(GLOBAL_bm_requestable_workers);
    BITMAP_clear(GLOBAL_bm_executing_workers);
    BITMAP_copy(GLOBAL_bm_finished_workers, GLOBAL_bm_present_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_idle_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_root_cp_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_invisible_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_requestable_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_executing_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_finished_workers);
#ifdef TABLING_INNER_CUTS
    INIT_LOCK(GLOBAL_LOCKS_bm_pruning_workers);
#endif /* TABLING_INNER_CUTS */
    GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS;
    INIT_LOCK(GLOBAL_LOCKS_heap_access);
    INIT_LOCK(GLOBAL_LOCKS_alloc_block);
#if defined(YAPOR_ERRORS) || defined(TABLING_ERRORS)
    INIT_LOCK(GLOBAL_LOCKS_stderr_messages);
#endif /* YAPOR_ERRORS || TABLING_ERRORS */
    if (number_workers == 1)
        PARALLEL_EXECUTION_MODE = FALSE;
    else
        PARALLEL_EXECUTION_MODE = TRUE;
#endif /* YAPOR */

#ifdef TABLING
    /* global data related to tabling */
    GLOBAL_root_tab_ent = NULL;
#ifdef GLOBAL_TRIE
    new_global_trie_node(GLOBAL_root_gt, 0, NULL, NULL, NULL);
#endif /* GLOBAL_TRIE */
#ifdef LIMIT_TABLING
    GLOBAL_first_sg_fr = NULL;
    GLOBAL_last_sg_fr = NULL;
    GLOBAL_check_sg_fr = NULL;
#endif /* LIMIT_TABLING */
    GLOBAL_root_dep_fr = NULL;
    for (i = 0; i < MAX_TABLE_VARS; i++) {
        CELL *pt = GLOBAL_table_var_enumerator_addr(i);
        RESET_VARIABLE(pt);
    }
#ifdef TABLE_LOCK_AT_WRITE_LEVEL
    for (i = 0; i < TABLE_LOCK_BUCKETS; i++)
        INIT_LOCK(GLOBAL_table_lock(i));
#endif /* TABLE_LOCK_AT_WRITE_LEVEL */
#endif /* TABLING */

    return;
}
Esempio n. 2
0
void Yap_init_global_optyap_data(int max_table_size, int n_workers,
                                 int sch_loop, int delay_load) {
  int i;

/* global data related to memory management */
#ifdef USE_PAGES_MALLOC
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_alloc, void *);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_void, void *);
#endif /* USE_PAGES_MALLOC */
#ifdef TABLING
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tab_ent, struct table_entry);
#if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_ent, struct subgoal_entry);
#endif
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_fr, struct subgoal_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_dep_fr, struct dependency_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_node, struct subgoal_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_hash, struct subgoal_trie_hash);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_node, struct answer_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_hash, struct answer_trie_hash);
#if defined(THREADS_FULL_SHARING)
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_ref_node, struct answer_ref_node);
#endif
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_gt_node, struct global_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_gt_hash, struct global_trie_hash);
#endif /* TABLING */
#ifdef YAPOR
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_or_fr, struct or_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_qg_sol_fr,
                         struct query_goal_solution_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_qg_ans_fr,
                         struct query_goal_answer_frame);
#ifdef TABLING
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_susp_fr, struct suspension_frame);
#endif
#ifdef TABLING_INNER_CUTS
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tg_sol_fr,
                         struct table_subgoal_solution_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tg_ans_fr,
                         struct table_subgoal_answer_frame);
#endif
#endif /* YAPOR */

#ifdef YAPOR
  /* global static data */
  GLOBAL_number_workers = n_workers;
  GLOBAL_worker_pid(0) = getpid();
  for (i = 1; i < GLOBAL_number_workers; i++)
    GLOBAL_worker_pid(i) = 0;
  GLOBAL_scheduler_loop = sch_loop;
  GLOBAL_delayed_release_load = delay_load;

  /* global data related to or-parallelism */
  ALLOC_OR_FRAME(GLOBAL_root_or_fr);
  BITMAP_clear(GLOBAL_bm_present_workers);
  for (i = 0; i < GLOBAL_number_workers; i++)
    BITMAP_insert(GLOBAL_bm_present_workers, i);
  BITMAP_copy(GLOBAL_bm_idle_workers, GLOBAL_bm_present_workers);
  BITMAP_clear(GLOBAL_bm_root_cp_workers);
  BITMAP_clear(GLOBAL_bm_invisible_workers);
  BITMAP_clear(GLOBAL_bm_requestable_workers);
  BITMAP_copy(GLOBAL_bm_finished_workers, GLOBAL_bm_present_workers);
  INIT_LOCK(GLOBAL_locks_bm_idle_workers);
  INIT_LOCK(GLOBAL_locks_bm_root_cp_workers);
  INIT_LOCK(GLOBAL_locks_bm_invisible_workers);
  INIT_LOCK(GLOBAL_locks_bm_requestable_workers);
  INIT_LOCK(GLOBAL_locks_bm_finished_workers);
#ifdef TABLING_INNER_CUTS
  INIT_LOCK(GLOBAL_locks_bm_pruning_workers);
#endif /* TABLING_INNER_CUTS */
  GLOBAL_locks_who_locked_heap = MAX_WORKERS;
  INIT_LOCK(GLOBAL_locks_heap_access);
  INIT_LOCK(GLOBAL_locks_alloc_block);
  if (GLOBAL_number_workers == 1)
    GLOBAL_parallel_mode = PARALLEL_MODE_OFF;
  else
    GLOBAL_parallel_mode = PARALLEL_MODE_ON;
#endif /* YAPOR */

#ifdef TABLING
  /* global data related to tabling */
  GLOBAL_root_gt = NULL;
  GLOBAL_root_tab_ent = NULL;
#ifdef LIMIT_TABLING
  if (max_table_size)
    GLOBAL_max_pages = ((max_table_size - 1) * 1024 * 1024 / SHMMAX + 1) *
                       SHMMAX / Yap_page_size;
  else
    GLOBAL_max_pages = -1;
  GLOBAL_first_sg_fr = NULL;
  GLOBAL_last_sg_fr = NULL;
  GLOBAL_check_sg_fr = NULL;
#endif /* LIMIT_TABLING */
#ifdef YAPOR
  new_dependency_frame(GLOBAL_root_dep_fr, FALSE, NULL, NULL, NULL, NULL, FALSE,
                       NULL);
#endif /* YAPOR */
  for (i = 0; i < MAX_TABLE_VARS; i++) {
    CELL *pt = GLOBAL_table_var_enumerator_addr(i);
    RESET_VARIABLE(pt);
  }
#ifdef TRIE_LOCK_USING_GLOBAL_ARRAY
  for (i = 0; i < TRIE_LOCK_BUCKETS; i++)
    INIT_LOCK(GLOBAL_trie_locks(i));
#endif /* TRIE_LOCK_USING_GLOBAL_ARRAY */
#endif /* TABLING */

  return;
}