Ejemplo n.º 1
0
Archivo: other.c Proyecto: jfmc/yap-6.3
Term 
Yap_MkNewPairTerm(void)
{
  CACHE_REGS
  register CELL  *p = HR;

  RESET_VARIABLE(HR);
  RESET_VARIABLE(HR+1);
  HR+=2;
  return (AbsPair(p));
}
Ejemplo n.º 2
0
void Array::__GO_GARBAGE(void *PIF, GarbageCollector *__gc_obj, GarbageCollector *__gc_array, GarbageCollector *__gc_vars, signed char check_objects) {
    if (this->LINKS < 0)
        return;

    this->LINKS = -1;
    NODE *CURRENT = FIRST;

    for (ARRAY_COUNT_TYPE i = 0; i < NODE_COUNT; i++) {
        for (ARRAY_COUNT_TYPE j = 0; j < CURRENT->COUNT; j++) {
            VariableDATA *Var = CURRENT->ELEMENTS [j];
            if (Var) {
                if (check_objects == -1) {
                    Var->LINKS++;
                    __gc_vars->Reference(Var);
                } else {
                    if (Var->LINKS <= 1)
                        __gc_vars->Reference(Var);
                    else
                        Var->LINKS--;
                }
                if (Var->CLASS_DATA) {
                    if ((Var->TYPE == VARIABLE_CLASS) || (Var->TYPE == VARIABLE_DELEGATE)) {
                        if ((check_objects == -1) || ((((CompiledClass *)Var->CLASS_DATA)->reachable & check_objects) != check_objects)) {
                            __gc_obj->Reference(Var->CLASS_DATA);
                            ((CompiledClass *)Var->CLASS_DATA)->__GO_GARBAGE(PIF, __gc_obj, __gc_array, __gc_vars, check_objects);
                        } else {
                            RESET_VARIABLE(Var);
                        }
                    } else
                    if (Var->TYPE == VARIABLE_ARRAY) {
                        if ((check_objects == -1) || ((((Array *)Var->CLASS_DATA)->reachable & check_objects) != check_objects)) {
                            __gc_array->Reference(Var->CLASS_DATA);
                            ((Array *)Var->CLASS_DATA)->__GO_GARBAGE(PIF, __gc_obj, __gc_array, __gc_vars, check_objects);
                        } else {
                            RESET_VARIABLE(Var);
                        }
                    }
                }
            }
        }
        CURRENT = CURRENT->NEXT;
    }
}
Ejemplo n.º 3
0
static Int
p_stream_to_codes(void)
{
  int sno = Yap_CheckStream (ARG1, Input_Stream_f, "read_line_to_codes/2");
  CELL *HBASE = H;
  CELL *h0 = &ARG4;

  if (sno < 0)
    return FALSE;
  while (!(Stream[sno].status & Eof_Stream_f)) {
    /* skip errors */
    Int ch = Stream[sno].stream_getc(sno);
    Term t;
    if (ch == EOFCHAR)
      break;
    t = MkIntegerTerm(ch);
    h0[0] = AbsPair(H);
    *H = t;
    H+=2;
    h0 = H-1;
    if (H >= ASP-1024) {
      RESET_VARIABLE(h0);
      ARG4 = AbsPair(HBASE);
      ARG5 = (CELL)h0;
      if (!Yap_gcl((ASP-HBASE)*sizeof(CELL), 5, ENV, gc_P(P,CP))) {
	Yap_Error(OUT_OF_STACK_ERROR, ARG1, "read_stream_to_codes/3");
	return FALSE;
      }
      /* build a legal term again */
      h0 = (CELL *)ARG5;
      HBASE = RepPair(ARG4);
    }
  }
  UNLOCK(Stream[sno].streamlock);
  if (H == HBASE)
    return Yap_unify(ARG2,ARG3);
  RESET_VARIABLE(H-1);
  Yap_unify(H[-1],ARG3);
  return Yap_unify(AbsPair(HBASE),ARG2);
    
}
Ejemplo n.º 4
0
static Int read_stream_to_codes(USES_REGS1) {
  int sno = Yap_CheckStream(ARG1, Input_Stream_f,
                            "reaMkAtomTerm (AtomEofd_line_to_codes/2");
  CELL *HBASE = HR;
  CELL *h0 = &ARG4;

  if (sno < 0)
    return FALSE;
  while (!(GLOBAL_Stream[sno].status & Eof_Stream_f)) {
    /* skip errors */
    Int ch = GLOBAL_Stream[sno].stream_getc(sno);
    Term t;
    if (ch == EOFCHAR)
      break;
    t = MkIntegerTerm(ch);
    h0[0] = AbsPair(HR);
    *HR = t;
    HR += 2;
    h0 = HR - 1;
    yhandle_t news, news1, st = Yap_StartSlots();
    if (HR >= ASP - 1024) {
      RESET_VARIABLE(h0);
      news = Yap_InitSlot(AbsPair(HBASE));
      news1 = Yap_InitSlot((CELL)(h0));
      if (!Yap_gcl((ASP - HBASE) * sizeof(CELL), 3, ENV, Yap_gcP())) {
        Yap_Error(RESOURCE_ERROR_STACK, ARG1, "read_stream_to_codes/3");
        return false;
      }
      /* build a legal term again */
      h0 = (CELL *)(Yap_GetFromSlot(news1));
      HBASE = RepPair(Yap_GetFromSlot(news));
    }
    Yap_CloseSlots(st);
  }
  UNLOCK(GLOBAL_Stream[sno].streamlock);
  if (HR == HBASE)
    return Yap_unify(ARG2, ARG3);
  RESET_VARIABLE(HR - 1);
  Yap_unify(HR[-1], ARG3);
  return Yap_unify(AbsPair(HBASE), ARG2);
}
Ejemplo n.º 5
0
static void
reset_trail(tr_fr_ptr tr_top, tr_fr_ptr trp)
{
  register CELL aux_cell;

  /* unbinding variables */
  while (tr_top != trp) {
    aux_cell = TrailTerm(--trp);
    /* check for global or local variables */
    if (IsVarTerm(aux_cell)) {
      /* clean up the trail when we backtrack */
      /* shouldn't this test always succeed? */
      if (Unsigned((Int)(aux_cell)-(Int)(H_FZ)) >
	  Unsigned((Int)(B_FZ)-(Int)(H_FZ))) {
	RESET_VARIABLE(STACK_TO_SBA(aux_cell));
      } else {
	RESET_VARIABLE(aux_cell);
      }
    }
    else if (IsPairTerm(aux_cell)) {
      /* avoid frozen segments */
      if ((ADDR) RepPair(aux_cell) > HeapTop) {
	trp = (tr_fr_ptr) RepPair(aux_cell);
      }
#ifdef MULTI_ASSIGNMENT_VARIABLES
    } else {
      CELL *aux_ptr = RepAppl(aux_cell);
      trp--;
      if (Unsigned((Int)(aux_ptr)-(Int)(H_FZ)) >
	  Unsigned((Int)(B_FZ)-(Int)(H_FZ))) {
	*STACK_TO_SBA(aux_ptr) = TrailTerm(trp);
      } else {
	*aux_ptr = TrailTerm(trp);
      }
#endif /* MULTI_ASSIGNMENT_VARIABLES */
    }
  }
}
Ejemplo n.º 6
0
Archivo: other.c Proyecto: jfmc/yap-6.3
Term 
Yap_MkNewApplTerm(Functor f, unsigned int n)	
     /* build compound term with functor f and n
      * args a */
{
  CACHE_REGS
  CELL           *t = HR;

  if (n == 0)
    return (MkAtomTerm(NameOfFunctor(f)));
  if (f == FunctorList) {
    RESET_VARIABLE(HR);
    RESET_VARIABLE(HR+1);
    HR+=2;
    return (AbsPair(t));
  }
  *HR++ = (CELL) f;
  while (n--) {
    RESET_VARIABLE(HR);
    HR++;
  }
  return (AbsAppl(t));
}
Ejemplo n.º 7
0
static Int read_stream_to_terms(USES_REGS1) {
  int sno = Yap_CheckStream(ARG1, Input_Stream_f, "read_line_to_codes/2");
  Term t, hd;
  yhandle_t tails, news;

  if (sno < 0)
    return FALSE;

  t = AbsPair(HR);
  RESET_VARIABLE(HR);
  Yap_InitSlot((CELL)(HR));
  tails = Yap_InitSlot((CELL)(HR));
  news = Yap_InitSlot((CELL)(HR));
  HR++;

  while (!(GLOBAL_Stream[sno].status & Eof_Stream_f)) {
    RESET_VARIABLE(HR);
    RESET_VARIABLE(HR + 1);
    hd = (CELL)HR;
    Yap_PutInSlot(news, (CELL)(HR + 1));
    HR += 2;
    while ((hd = Yap_read_term(sno, TermNil, 2)) == 0L)
      ;
    // just ignore failure
    CELL *pt = VarOfTerm(Yap_GetFromSlot(tails));
    if (Deref(hd) == TermEOfCode) {
      *pt = Deref(ARG3);
      break;
    } else {
      CELL *newpt = (CELL *)Yap_GetFromSlot(news);
      *pt = AbsPair(newpt - 1);
      Yap_PutInSlot(tails, (CELL)newpt);
    }
  }
  UNLOCK(GLOBAL_Stream[sno].streamlock);
  return Yap_unify(t, ARG2);
}
Ejemplo n.º 8
0
static CELL *InitHandles(int wid) {
  size_t initial_slots = 1024;
  CELL *handles;

  REMOTE_CurSlot(wid) = 1;
  REMOTE_NSlots(wid) = initial_slots;
  handles = calloc(initial_slots, sizeof(CELL));

  if (handles == NULL) {
    Yap_Error(SYSTEM_ERROR_INTERNAL, 0 /* TermNil */,
              "No space for handles at " __FILE__ " : %d", __LINE__);
  }

  RESET_VARIABLE(handles);
  return handles;
}
Ejemplo n.º 9
0
static Term
NewTimedVar(CELL val USES_REGS)
{
  Term out;
  timed_var *tv;
  if (IsVarTerm(val) &&
      VarOfTerm(val) > H) {
    Term nval = MkVarTerm();
    Bind_Local(VarOfTerm(val), nval);
    val = nval;
  }
  out = AbsAppl(H);
  *H++ = (CELL)FunctorMutable;
  tv = (timed_var *)H;
  RESET_VARIABLE(&(tv->clock));
  tv->value = val;
  H += sizeof(timed_var)/sizeof(CELL);
  return(out);
}
Ejemplo n.º 10
0
int
Yap_Unifiable( Term d0, Term d1 )
{
  CACHE_REGS
  tr_fr_ptr trp, trp0 = TR;

  if (!unifiable(d0,d1)) {
    return FALSE;
  }
  trp = TR;
  while (trp != trp0) {
    Term t;

    --trp;
    t = TrailTerm(trp);
    RESET_VARIABLE(t);
  }
  return TRUE;
}
Ejemplo n.º 11
0
static Int
p_unifiable( USES_REGS1 )
{
  tr_fr_ptr trp, trp0 = TR;
  Term tf = TermNil;
  if (!unifiable(ARG1,ARG2)) {
    return FALSE;
  }
  trp = TR;
  while (trp != trp0) {
    Term t[2];
    --trp;
    t[0] = TrailTerm(trp);
    t[1] = *(CELL *)t[0];
    tf = MkPairTerm(Yap_MkApplTerm(FunctorEq,2,t),tf);
    RESET_VARIABLE(t[0]);
  }
  return Yap_unify(ARG3, tf);
}
Ejemplo n.º 12
0
static int unbind_variable_names(Term t USES_REGS) {
  while (!IsVarTerm(t) && IsPairTerm(t)) {
    Term tl = HeadOfTerm(t);
    Functor f;
    Term *tp2, t1;

    if (!IsApplTerm(tl))
      return FALSE;
    if ((f = FunctorOfTerm(tl)) != FunctorEq) {
      return FALSE;
    }
    t1 = ArgOfTerm(1, tl);
    tp2 = RepAppl(tl) + 2;
    while (*tp2 != t1) {
      tp2 = (CELL *)*tp2;
    }
    RESET_VARIABLE(tp2);
    t = TailOfTerm(t);
  }
  return TRUE;
}
Ejemplo n.º 13
0
int q_share_work(int worker_p) {
  register tr_fr_ptr aux_tr;
  register CELL aux_cell;

  LOCK_OR_FRAME(LOCAL_top_or_fr);
  if (REMOTE_prune_request(worker_p)) {
    /* worker p with prune request */
    UNLOCK_OR_FRAME(LOCAL_top_or_fr);
    return FALSE;
  }
  YAPOR_ERROR_CHECKING(q_share_work, Get_OrFr_pend_prune_cp(LOCAL_top_or_fr) && BRANCH_LTT(worker_p, OrFr_depth(LOCAL_top_or_fr)) < OrFr_pend_prune_ltt(LOCAL_top_or_fr));
  /* there is no pending prune with worker p at right --> safe move to worker p branch */
  CUT_reset_prune_request();
  if(Get_LOCAL_prune_request()){
   UNLOCK_OR_FRAME(LOCAL_top_or_fr);
   return FALSE;
  }
  BRANCH(worker_id, OrFr_depth(LOCAL_top_or_fr)) = BRANCH(worker_p, OrFr_depth(LOCAL_top_or_fr));
  UNLOCK_OR_FRAME(LOCAL_top_or_fr);

  /* unbind variables */
  aux_tr = LOCAL_top_cp->cp_tr;
  TABLING_ERROR_CHECKING(q_share_work, TR < aux_tr);
  while (aux_tr != TR) {
    aux_cell = TrailTerm(--TR);
    /* check for global or local variables */
    if (IsVarTerm(aux_cell)) {
      RESET_VARIABLE(aux_cell);
#ifdef TABLING
    } else if (IsPairTerm(aux_cell)) {
      aux_cell = (CELL) RepPair(aux_cell);
      if (IN_BETWEEN(LOCAL_TrailBase, aux_cell, LOCAL_TrailTop)) {
	/* avoid frozen segments */
        TR = (tr_fr_ptr) aux_cell;
	TABLING_ERROR_CHECKING(q_share_work, TR > (tr_fr_ptr) LOCAL_TrailTop);
	TABLING_ERROR_CHECKING(q_share_work, TR < aux_tr);
      }
#endif /* TABLING */
#ifdef MULTI_ASSIGNMENT_VARIABLES
    } else if (IsApplTerm(aux_cell)) {
      CELL *aux_ptr = RepAppl(aux_cell);
      Term aux_val = TrailTerm(--aux_tr);
      *aux_ptr = aux_val;
#endif /* MULTI_ASSIGNMENT_VARIABLES */
    }
  }

  OPTYAP_ERROR_CHECKING(q_share_work, LOCAL_top_cp != LOCAL_top_cp_on_stack);
  OPTYAP_ERROR_CHECKING(q_share_work, YOUNGER_CP(B_FZ, LOCAL_top_cp));
  YAPOR_ERROR_CHECKING(q_share_work, LOCAL_reply_signal != worker_ready);

  /* make sharing request */
  LOCK_WORKER(worker_p);
  if (BITMAP_member(GLOBAL_bm_idle_workers, worker_p) || 
      REMOTE_share_request(worker_p) != MAX_WORKERS) {
    /* worker p is idle or has another request */
    UNLOCK_WORKER(worker_p);
    return FALSE;
  }
  REMOTE_share_request(worker_p) = worker_id;
  UNLOCK_WORKER(worker_p);

  /* wait for an answer */
  while (LOCAL_reply_signal == worker_ready);
  if (LOCAL_reply_signal == no_sharing) {
    /* sharing request refused */
    LOCAL_reply_signal = worker_ready;
    return FALSE;
  }

  /* copy trail stack ? */
  LOCK(LOCAL_lock_signals);
  if (LOCAL_p_fase_signal > trail) {
    LOCAL_q_fase_signal = trail;
    UNLOCK(LOCAL_lock_signals);
    Q_COPY_TRAIL_FROM(worker_p);
  } else {
    UNLOCK(LOCAL_lock_signals);
    goto sync_with_p;
  }

  /* copy global stack ? */
  LOCK(LOCAL_lock_signals);
  if (LOCAL_p_fase_signal > global) {
    LOCAL_q_fase_signal = global;
    UNLOCK(LOCAL_lock_signals);
    Q_COPY_GLOBAL_FROM(worker_p);
  } else {
    UNLOCK(LOCAL_lock_signals);
    goto sync_with_p;
  }

  /* copy local stack ? */
  while (LOCAL_reply_signal < nodes_shared);
  LOCK(LOCAL_lock_signals);
  if (LOCAL_p_fase_signal > local) {
    LOCAL_q_fase_signal = local;
    UNLOCK(LOCAL_lock_signals);
    Q_COPY_LOCAL_FROM(worker_p);
  } else UNLOCK(LOCAL_lock_signals);

sync_with_p:
#ifdef TABLING
  REMOTE_reply_signal(worker_p) = worker_ready;
#else
  REMOTE_reply_signal(worker_p) = copy_done;
#endif /* TABLING */
  while (LOCAL_reply_signal != copy_done);

#if INCREMENTAL_COPY
  /* install fase --> TR and LOCAL_top_cp->cp_tr are equal */
  aux_tr = ((choiceptr) LOCAL_start_local_copy)->cp_tr;
  TR = ((choiceptr) LOCAL_end_local_copy)->cp_tr;
  Yap_NEW_MAHASH((ma_h_inner_struct *)HR);
  while (TR != aux_tr) {
    aux_cell = TrailTerm(--aux_tr);
    if (IsVarTerm(aux_cell)) {
      if (aux_cell < LOCAL_start_global_copy || EQUAL_OR_YOUNGER_CP((choiceptr)LOCAL_end_local_copy, (choiceptr)aux_cell)) {
	YAPOR_ERROR_CHECKING(q_share_work, (CELL *)aux_cell < H0);
	YAPOR_ERROR_CHECKING(q_share_work, (ADDR)aux_cell > LOCAL_LocalBase);
#ifdef TABLING
        *((CELL *) aux_cell) = TrailVal(aux_tr);
#else
        *((CELL *) aux_cell) = *((CELL *) (worker_offset(worker_p) + aux_cell));
#endif /* TABLING */
      }
#ifdef TABLING 
    } else if (IsPairTerm(aux_cell)) {
      aux_cell = (CELL) RepPair(aux_cell);
      if (IN_BETWEEN(LOCAL_TrailBase, aux_cell, LOCAL_TrailTop)) {
        /* avoid frozen segments */
        aux_tr = (tr_fr_ptr) aux_cell;
      }
#endif /* TABLING */
#ifdef MULTI_ASSIGNMENT_VARIABLES
    } else if (IsApplTerm(aux_cell)) {
      CELL *cell_ptr = RepAppl(aux_cell);
      if (((CELL *)aux_cell < LOCAL_top_cp->cp_h || 
          EQUAL_OR_YOUNGER_CP(LOCAL_top_cp, (choiceptr)aux_cell)) &&
	  !Yap_lookup_ma_var(cell_ptr)) {
	/* first time we found the variable, let's put the new value */
#ifdef TABLING
        *cell_ptr = TrailVal(aux_tr);
#else
        *cell_ptr = *((CELL *) (worker_offset(worker_p) + (CELL)cell_ptr));
#endif /* TABLING */
      }
      /* skip the old value */
      aux_tr--;
#endif /* MULTI_ASSIGNMENT_VARIABLES */
    }
  }
#endif /* incremental */

  /* update registers and return */
  PUT_OUT_ROOT_NODE(worker_id);
#ifndef TABLING
  REMOTE_reply_signal(worker_p) = worker_ready;
#endif /* TABLING */
  TR = (tr_fr_ptr) LOCAL_end_trail_copy;
  LOCAL_reply_signal = worker_ready;
  PUT_IN_REQUESTABLE(worker_id);
#ifdef TABLING
  adjust_freeze_registers();
#endif /* TABLING */
  return TRUE;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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;
}