Example #1
0
void make_root_frames(void) {
#ifdef YAPOR
    /* root or frame */
    or_fr_ptr or_fr;

    ALLOC_OR_FRAME(or_fr);
    INIT_LOCK(OrFr_lock(or_fr));
    OrFr_alternative(or_fr) = NULL;
    BITMAP_copy(OrFr_members(or_fr), GLOBAL_bm_present_workers);
    SetOrFr_node(or_fr, (choiceptr) Yap_LocalBase);
    OrFr_nearest_livenode(or_fr) = NULL;
    OrFr_depth(or_fr) = 0;
    Set_OrFr_pend_prune_cp(or_fr, NULL);
    OrFr_nearest_leftnode(or_fr) = or_fr;
    OrFr_qg_solutions(or_fr) = NULL;
#ifdef TABLING_INNER_CUTS
    OrFr_tg_solutions(or_fr) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
    OrFr_owners(or_fr) = number_workers;
    OrFr_next_on_stack(or_fr) = NULL;
    OrFr_suspensions(or_fr) = NULL;
    OrFr_nearest_suspnode(or_fr) = or_fr;
#endif /* TABLING */
    OrFr_next(or_fr) = NULL;
    GLOBAL_root_or_fr = or_fr;
#endif /* YAPOR */

#ifdef TABLING
    /* root dependency frame */
    if (!GLOBAL_root_dep_fr) {
        new_dependency_frame(GLOBAL_root_dep_fr, FALSE, NULL, NULL, NULL, NULL, NULL);
    }
#endif /* TABLING */
}
Example #2
0
void complete_suspension_frames(or_fr_ptr or_fr) {
  CACHE_REGS
  dep_fr_ptr chain_dep_fr;
  or_fr_ptr chain_or_fr;
  susp_fr_ptr susp_fr;
  qg_sol_fr_ptr solutions;

  /* complete suspension frames */
  chain_dep_fr = NULL;
  chain_or_fr = NULL;
  susp_fr = OrFr_suspensions(or_fr);
  do {
    susp_fr_ptr next_susp_fr;
    complete_suspension_branch(susp_fr, GetOrFr_node(or_fr), &chain_or_fr, &chain_dep_fr);
    next_susp_fr = SuspFr_next(susp_fr);
    FREE_SUSPENSION_FRAME(susp_fr);
    susp_fr = next_susp_fr;
  } while (susp_fr);
  OrFr_suspensions(or_fr) = NULL;
  OrFr_nearest_suspnode(or_fr) = or_fr;

  /* release dependency frames */
  while (chain_dep_fr) {
    dep_fr_ptr next_dep_fr;
    next_dep_fr = DepFr_next(chain_dep_fr);
    FREE_DEPENDENCY_FRAME(chain_dep_fr);
    chain_dep_fr = next_dep_fr;
  }

  /* release or frames */
  solutions = NULL;
  while (chain_or_fr) {
    or_fr_ptr next_or_fr;
    qg_sol_fr_ptr aux_solutions;
    aux_solutions = OrFr_qg_solutions(chain_or_fr);
    if (aux_solutions) {
      CUT_join_answers_in_an_unique_frame(aux_solutions);
      SolFr_next(aux_solutions) = solutions;
      solutions = aux_solutions;
    }
    next_or_fr = OrFr_next_on_stack(chain_or_fr);
    FREE_OR_FRAME(chain_or_fr);
    chain_or_fr = next_or_fr;
  }
  if (solutions) {
    CUT_join_answers_in_an_unique_frame(solutions);
    SolFr_next(solutions) = OrFr_qg_solutions(or_fr);
    OrFr_qg_solutions(LOCAL_top_or_fr) = solutions;
  }

  return;
}
Example #3
0
void Yap_init_root_frames(void) {
  CACHE_REGS

#ifdef YAPOR
  /* root or frame */
  or_fr_ptr or_fr = GLOBAL_root_or_fr;
  INIT_LOCK(OrFr_lock(or_fr));
  OrFr_alternative(or_fr) = NULL;
  BITMAP_copy(OrFr_members(or_fr), GLOBAL_bm_present_workers);
  SetOrFr_node(or_fr, (choiceptr)LOCAL_LocalBase);
  OrFr_nearest_livenode(or_fr) = NULL;
  OrFr_depth(or_fr) = 0;
  Set_OrFr_pend_prune_cp(or_fr, NULL);
  OrFr_nearest_leftnode(or_fr) = or_fr;
  OrFr_qg_solutions(or_fr) = NULL;
#ifdef TABLING_INNER_CUTS
  OrFr_tg_solutions(or_fr) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
  OrFr_owners(or_fr) = GLOBAL_number_workers;
  OrFr_next_on_stack(or_fr) = NULL;
  OrFr_suspensions(or_fr) = NULL;
  OrFr_nearest_suspnode(or_fr) = or_fr;
#endif /* TABLING */
  OrFr_next(or_fr) = NULL;
#endif /* YAPOR */

#ifdef TABLING
  /* root global trie node */
  new_global_trie_node(GLOBAL_root_gt, 0, NULL, NULL, NULL);
/* root dependency frame */
#ifdef YAPOR
  DepFr_cons_cp(GLOBAL_root_dep_fr) = B; /* with YAPOR, at that point,
                                            LOCAL_top_dep_fr shouldn't be the
                                            same as GLOBAL_root_dep_fr ? */
#else
  new_dependency_frame(LOCAL_top_dep_fr, FALSE, NULL, NULL, B, NULL, FALSE,
                       NULL);
#endif /* YAPOR */
#endif /* TABLING */
}
Example #4
0
static
void share_private_nodes(int worker_q) {
  choiceptr sharing_node = B;

#ifdef DEBUG_OPTYAP
  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(LOCAL_top_cp, LOCAL_top_cp_on_stack));
  { choiceptr aux_cp = B;
    while (aux_cp != LOCAL_top_cp) {
      OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(LOCAL_top_cp, aux_cp));
      OPTYAP_ERROR_CHECKING(share_private_nodes, EQUAL_OR_YOUNGER_CP(LOCAL_top_cp_on_stack, aux_cp));
      aux_cp = aux_cp->cp_b;
    }
  }
#endif /* DEBUG_OPTYAP */

#ifdef TABLING
  /* check if the branch is already shared */
  if (EQUAL_OR_YOUNGER_CP(LOCAL_top_cp_on_stack, sharing_node)) {
    or_fr_ptr or_frame;
    sg_fr_ptr sg_frame;
    dep_fr_ptr dep_frame;

#ifdef DEBUG_OPTYAP
    { or_fr_ptr aux_or_fr;
      aux_or_fr = LOCAL_top_or_fr;
      while (aux_or_fr != REMOTE_top_or_fr(worker_q)) {
	OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(OrFr_node(REMOTE_top_or_fr(worker_q)), OrFr_node(aux_or_fr)));
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update old shared nodes */
    or_frame = LOCAL_top_or_fr;
    while (or_frame != REMOTE_top_or_fr(worker_q)) {
      LOCK_OR_FRAME(or_frame);
      BRANCH(worker_q, OrFr_depth(or_frame)) = BRANCH(worker_id, OrFr_depth(or_frame));
      OrFr_owners(or_frame)++;
      if (BITMAP_member(OrFr_members(or_frame), worker_id))
        BITMAP_insert(OrFr_members(or_frame), worker_q);
      UNLOCK_OR_FRAME(or_frame);
      or_frame = OrFr_next_on_stack(or_frame);
    }

    /* update worker Q top subgoal frame */
    sg_frame = LOCAL_top_sg_fr;
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), sharing_node)) {
      sg_frame = SgFr_next(sg_frame);
    }
    REMOTE_top_sg_fr(worker_q) = sg_frame;

    /* update worker Q top dependency frame */
    dep_frame = LOCAL_top_dep_fr;
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), sharing_node)) {
      dep_frame = DepFr_next(dep_frame);
    }
    REMOTE_top_dep_fr(worker_q) = dep_frame;

    /* update worker Q top shared nodes */
    REMOTE_top_cp_on_stack(worker_q) = REMOTE_top_cp(worker_q) = LOCAL_top_cp;
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr;
  } else
#endif /* TABLING */
  {
    int depth;
    bitmap bm_workers;
    or_fr_ptr or_frame, previous_or_frame;
#ifdef TABLING
    choiceptr consumer_cp, next_node_on_branch;
    dep_fr_ptr dep_frame;
    sg_fr_ptr sg_frame;
    CELL *stack, *stack_limit;

    /* find top dependency frame above current choice point */
    dep_frame = LOCAL_top_dep_fr;
    while (EQUAL_OR_YOUNGER_CP(DepFr_cons_cp(dep_frame), sharing_node)) {
      dep_frame = DepFr_next(dep_frame);
    }
    /* initialize tabling auxiliary variables */ 
    consumer_cp = DepFr_cons_cp(dep_frame);
    next_node_on_branch = NULL;
    stack_limit = (CELL *)TR;
    stack = (CELL *)LOCAL_TrailTop;
#endif /* TABLING */

    /* initialize auxiliary variables */
    BITMAP_clear(bm_workers);
    BITMAP_insert(bm_workers, worker_id);
    BITMAP_insert(bm_workers, worker_q);
    previous_or_frame = NULL;
    depth = OrFr_depth(LOCAL_top_or_fr);

    /* sharing loop */
#ifdef TABLING
    while (YOUNGER_CP(sharing_node, LOCAL_top_cp_on_stack)) {
#else
    while (sharing_node != LOCAL_top_cp) {
#endif /* TABLING */

#ifdef DEBUG_OPTYAP
      if (next_node_on_branch) {
        choiceptr aux_cp = B;
        while (aux_cp != next_node_on_branch) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, sharing_node == aux_cp);
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(next_node_on_branch, aux_cp));
          aux_cp = aux_cp->cp_b;
        }
      } else {
        choiceptr aux_cp = B;
        while (aux_cp != sharing_node) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(sharing_node, aux_cp));
          aux_cp = aux_cp->cp_b;
        }
      }
#endif /* DEBUG_OPTYAP */

      ALLOC_OR_FRAME(or_frame);
      if (previous_or_frame) {
#ifdef TABLING
        OrFr_next_on_stack(previous_or_frame) =
#endif /* TABLING */
        OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) = or_frame;
      }
      previous_or_frame = or_frame;
      depth++;
      INIT_LOCK(OrFr_lock(or_frame));
      OrFr_node(or_frame) = sharing_node;
      OrFr_alternative(or_frame) = sharing_node->cp_ap;
      OrFr_pend_prune_cp(or_frame) = NULL;
      OrFr_nearest_leftnode(or_frame) = LOCAL_top_or_fr;
      OrFr_qg_solutions(or_frame) = NULL;
#ifdef TABLING_INNER_CUTS
      OrFr_tg_solutions(or_frame) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
      OrFr_suspensions(or_frame) = NULL;
      OrFr_nearest_suspnode(or_frame) = or_frame;
      OrFr_owners(or_frame) = 2;
      if (next_node_on_branch)
        BITMAP_clear(OrFr_members(or_frame));
      else
#endif /* TABLING */
        OrFr_members(or_frame) = bm_workers;

      YAPOR_ERROR_CHECKING(share_private_nodes, sharing_node->cp_ap == GETWORK || sharing_node->cp_ap == GETWORK_SEQ);
      if (sharing_node->cp_ap && YAMOP_SEQ(sharing_node->cp_ap)) {
        sharing_node->cp_ap = GETWORK_SEQ;
      } else {
        sharing_node->cp_ap = GETWORK;
      }
      sharing_node->cp_or_fr = or_frame;
      sharing_node = sharing_node->cp_b;

#ifdef TABLING
      /* when next_node_on_branch is not NULL the **
      ** sharing_node belongs to a frozen branch. */   
      if (YOUNGER_CP(consumer_cp, sharing_node)) {
        /* frozen stack segment */
        if (! next_node_on_branch)
          next_node_on_branch = sharing_node;
        STACK_PUSH_UP(or_frame, stack);
        STACK_CHECK_EXPAND(stack, stack_limit);
        STACK_PUSH_UP(sharing_node, stack);
        STACK_CHECK_EXPAND(stack, stack_limit);
        sharing_node = consumer_cp;
        dep_frame = DepFr_next(dep_frame);
        consumer_cp = DepFr_cons_cp(dep_frame);
      } else if (consumer_cp == sharing_node) {
        dep_frame = DepFr_next(dep_frame);
        consumer_cp = DepFr_cons_cp(dep_frame);
      }
      if (next_node_on_branch == sharing_node)
        next_node_on_branch = NULL;
#endif /* TABLING */
      OPTYAP_ERROR_CHECKING(share_private_nodes, next_node_on_branch && YOUNGER_CP(next_node_on_branch, sharing_node));
    }

    /* initialize last or-frame pointer */
    or_frame = sharing_node->cp_or_fr;
    if (previous_or_frame) {
#ifdef TABLING
      OrFr_next_on_stack(previous_or_frame) =
#endif /* TABLING */
      OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) = or_frame;
    }

#ifdef TABLING
    /* update or-frames stored in auxiliary stack */
    while (STACK_NOT_EMPTY(stack, (CELL *)LOCAL_TrailTop)) {
      next_node_on_branch = (choiceptr) STACK_POP_DOWN(stack);
      or_frame = (or_fr_ptr) STACK_POP_DOWN(stack);
      OrFr_nearest_livenode(or_frame) = OrFr_next(or_frame) = next_node_on_branch->cp_or_fr;
    }
#endif /* TABLING */

    /* update depth */
    if (depth >= MAX_BRANCH_DEPTH)
      Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "maximum depth exceded (share_private_nodes)");
    or_frame = B->cp_or_fr;
#ifdef TABLING
    previous_or_frame = LOCAL_top_cp_on_stack->cp_or_fr;
    while (or_frame != previous_or_frame) {
#else
    while (or_frame != LOCAL_top_or_fr) {
#endif /* TABLING */
      unsigned int branch;
      if (OrFr_alternative(or_frame)) {
        branch = YAMOP_OR_ARG(OrFr_alternative(or_frame)) + 1;
      } else {
        branch = 1;
      }
      branch |= YAMOP_CUT_FLAG;  /* in doubt, assume cut */
      BRANCH(worker_id, depth) = BRANCH(worker_q, depth) = branch;
      OrFr_depth(or_frame) = depth--;
      or_frame = OrFr_next_on_stack(or_frame);
    }

    YAPOR_ERROR_CHECKING(share_private_nodes, depth != OrFr_depth(LOCAL_top_or_fr));

#ifdef DEBUG_OPTYAP
    { or_fr_ptr aux_or_fr = B->cp_or_fr;
      choiceptr aux_cp;
      while (aux_or_fr != LOCAL_top_cp_on_stack->cp_or_fr) {
        aux_cp = OrFr_node(aux_or_fr);
	OPTYAP_ERROR_CHECKING(share_private_nodes, OrFr_next(aux_or_fr) != aux_cp->cp_b->cp_or_fr);
	OPTYAP_ERROR_CHECKING(share_private_nodes, OrFr_nearest_livenode(aux_or_fr) != aux_cp->cp_b->cp_or_fr);
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
      aux_or_fr = B->cp_or_fr;
      while (aux_or_fr != LOCAL_top_cp_on_stack->cp_or_fr) {
        or_fr_ptr nearest_leftnode = OrFr_nearest_leftnode(aux_or_fr);
        aux_cp = OrFr_node(aux_or_fr);
        while (OrFr_node(nearest_leftnode) != aux_cp) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(OrFr_node(nearest_leftnode), aux_cp));
          aux_cp = aux_cp->cp_b;
        }
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update old shared nodes */
    while (or_frame != REMOTE_top_or_fr(worker_q)) {
      LOCK_OR_FRAME(or_frame);
      BRANCH(worker_q, OrFr_depth(or_frame)) = BRANCH(worker_id, OrFr_depth(or_frame));
#ifdef TABLING
      OrFr_owners(or_frame)++;
      if (BITMAP_member(OrFr_members(or_frame), worker_id))
#endif /* TABLING */
        BITMAP_insert(OrFr_members(or_frame), worker_q);
      UNLOCK_OR_FRAME(or_frame);
      or_frame = OrFr_next_on_stack(or_frame);
    }

    LOCK_OR_FRAME(REMOTE_top_or_fr(worker_q));
    or_fr_ptr old_top = REMOTE_top_or_fr(worker_q);
    Set_REMOTE_top_cp(worker_q,B);
    Set_LOCAL_top_cp(B);
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr = Get_LOCAL_top_cp()->cp_or_fr;
    UNLOCK_OR_FRAME(old_top);  

#ifdef TABLING
    /* update subgoal frames in the maintained private branches */
    sg_frame = LOCAL_top_sg_fr;
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), B)) {
      choiceptr top_cp_on_branch;
      top_cp_on_branch = SgFr_gen_cp(sg_frame);
      while (YOUNGER_CP(top_cp_on_branch, B)) {
        top_cp_on_branch = top_cp_on_branch->cp_b;
      }
      SgFr_gen_top_or_fr(sg_frame) = top_cp_on_branch->cp_or_fr;
      sg_frame = SgFr_next(sg_frame);
    }
    /* update worker Q top subgoal frame */
    REMOTE_top_sg_fr(worker_q) = sg_frame;
    /* update subgoal frames in the recently shared branches */
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), LOCAL_top_cp_on_stack)) {
      SgFr_gen_worker(sg_frame) = MAX_WORKERS;
      SgFr_gen_top_or_fr(sg_frame) = SgFr_gen_cp(sg_frame)->cp_or_fr;
      sg_frame = SgFr_next(sg_frame);
    }

    /* update dependency frames in the maintained private branches */
    dep_frame = LOCAL_top_dep_fr;
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), B)) {
      choiceptr top_cp_on_branch;
      top_cp_on_branch = DepFr_cons_cp(dep_frame);
      while (YOUNGER_CP(top_cp_on_branch, B)) {
        top_cp_on_branch = top_cp_on_branch->cp_b;
      }
      DepFr_top_or_fr(dep_frame) = top_cp_on_branch->cp_or_fr;
      dep_frame = DepFr_next(dep_frame);
    }
    /* update worker Q top dependency frame */
    REMOTE_top_dep_fr(worker_q) = dep_frame;
    /* update dependency frames in the recently shared branches */
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), LOCAL_top_cp_on_stack)) {
      DepFr_top_or_fr(dep_frame) = DepFr_cons_cp(dep_frame)->cp_or_fr;
      dep_frame = DepFr_next(dep_frame);
    }
#endif /* TABLING */

#ifdef DEBUG_OPTYAP
    { dep_fr_ptr aux_dep_fr = LOCAL_top_dep_fr;
      while(aux_dep_fr != GLOBAL_root_dep_fr) {
        choiceptr top_cp_on_branch;
        top_cp_on_branch = DepFr_cons_cp(aux_dep_fr);
        while (YOUNGER_CP(top_cp_on_branch, B)) {
          top_cp_on_branch = top_cp_on_branch->cp_b;
        }
	OPTYAP_ERROR_CHECKING(share_private_nodes, top_cp_on_branch->cp_or_fr != DepFr_top_or_fr(aux_dep_fr));
        aux_dep_fr = DepFr_next(aux_dep_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update top shared nodes */
#ifdef TABLING
    REMOTE_top_cp_on_stack(worker_q) = LOCAL_top_cp_on_stack = 
#endif /* TABLING */
    REMOTE_top_cp(worker_q) = LOCAL_top_cp = B;
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr = LOCAL_top_cp->cp_or_fr;
  }

#ifdef TABLING_INNER_CUTS
  /* update worker Q pruning scope */
  if (LOCAL_pruning_scope && EQUAL_OR_YOUNGER_CP(LOCAL_top_cp, LOCAL_pruning_scope)) {
    REMOTE_pruning_scope(worker_q) = LOCAL_pruning_scope;
    PUT_IN_PRUNING(worker_q);
  } else {
    PUT_OUT_PRUNING(worker_q);
    REMOTE_pruning_scope(worker_q) = NULL;
  }
#endif /* TABLING_INNER_CUTS */

  /* update worker Q prune request */
  if (LOCAL_prune_request) {
    CUT_send_prune_request(worker_q, LOCAL_prune_request);
  }

  /* update load and return */
  REMOTE_load(worker_q) = LOCAL_load = 0;
  return;
}
Example #5
0
void suspend_branch(void) {
  CACHE_REGS
  or_fr_ptr or_frame;

  /* suspension only occurs in shared nodes that **
  **   are leaders with younger consumer nodes   */
#ifdef DEBUG_OPTYAP
  OPTYAP_ERROR_CHECKING(suspend_branch, Get_LOCAL_top_cp()->cp_or_fr != LOCAL_top_or_fr);
  OPTYAP_ERROR_CHECKING(suspend_branch, B_FZ == Get_LOCAL_top_cp());
  OPTYAP_ERROR_CHECKING(suspend_branch, YOUNGER_CP(Get_LOCAL_top_cp(), Get_LOCAL_top_cp_on_stack()));
  OPTYAP_ERROR_CHECKING(suspend_branch, Get_LOCAL_top_cp()->cp_or_fr != LOCAL_top_or_fr);
  or_frame = Get_LOCAL_top_cp_on_stack()->cp_or_fr;
  while (or_frame != LOCAL_top_or_fr) {
    OPTYAP_ERROR_CHECKING(suspend_branch, YOUNGER_CP(Get_LOCAL_top_cp(), GetOrFr_node(or_frame)));
    or_frame = OrFr_next_on_stack(or_frame);
  }
#endif /* DEBUG_OPTYAP */

  or_frame = Get_LOCAL_top_cp_on_stack()->cp_or_fr;
  LOCK_OR_FRAME(or_frame);
  if (B_FZ == Get_LOCAL_top_cp_on_stack() && OrFr_owners(or_frame) > 1) {
    /* there are other workers sharing the whole branch **
    **         --> we can avoid suspension <--          */

    /* update shared nodes */
    OrFr_owners(or_frame)--;
    UNLOCK_OR_FRAME(or_frame);
    or_frame = OrFr_next_on_stack(or_frame);
    while (or_frame != LOCAL_top_or_fr) {
      LOCK_OR_FRAME(or_frame);
      OrFr_owners(or_frame)--;
      UNLOCK_OR_FRAME(or_frame);
      or_frame = OrFr_next_on_stack(or_frame);
    }
  } else {
    /* the branch has private parts **
    **    --> suspend branch <--    */
    susp_fr_ptr new_susp_fr;
    long h_size, b_size, tr_size;
    UNLOCK_OR_FRAME(or_frame);

    /* alloc suspension frame */
    h_size = (unsigned long) H_FZ - (unsigned long) Get_LOCAL_top_cp()->cp_h;
    b_size = (unsigned long) Get_LOCAL_top_cp() - (unsigned long) B_FZ;
    tr_size = (unsigned long) TR_FZ - (unsigned long) Get_LOCAL_top_cp()->cp_tr;
    new_suspension_frame(new_susp_fr, Get_LOCAL_top_cp_on_stack()->cp_or_fr, LOCAL_top_dep_fr, LOCAL_top_sg_fr,
                         Get_LOCAL_top_cp()->cp_h, B_FZ, Get_LOCAL_top_cp()->cp_tr, h_size, b_size, tr_size);

    /* store suspension frame in current top or-frame */
    LOCK_OR_FRAME(LOCAL_top_or_fr);
    if (OrFr_nearest_suspnode(LOCAL_top_or_fr) == LOCAL_top_or_fr)
      OrFr_nearest_suspnode(LOCAL_top_or_fr) = NULL;
    SuspFr_next(new_susp_fr) = OrFr_suspensions(LOCAL_top_or_fr);
    OrFr_suspensions(LOCAL_top_or_fr) = new_susp_fr;
    UNLOCK_OR_FRAME(LOCAL_top_or_fr);
  }

  /* adjust top pointers */
  while (LOCAL_top_sg_fr && YOUNGER_CP(SgFr_gen_cp(LOCAL_top_sg_fr), Get_LOCAL_top_cp_on_stack())) {
    SgFr_gen_worker(LOCAL_top_sg_fr) = MAX_WORKERS;
    LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);
  }
  while (LOCAL_top_sg_fr && YOUNGER_CP(SgFr_gen_cp(LOCAL_top_sg_fr), Get_LOCAL_top_cp())) {
    LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);
  }
  while (YOUNGER_CP(DepFr_cons_cp(LOCAL_top_dep_fr), Get_LOCAL_top_cp())) {
    LOCAL_top_dep_fr = DepFr_next(LOCAL_top_dep_fr);
  }
  Set_LOCAL_top_cp_on_stack( Get_LOCAL_top_cp() );

  /* adjust freeze registers */
  adjust_freeze_registers();

  return;
}
Example #6
0
void public_completion(void) {
  CACHE_REGS
  dep_fr_ptr chain_dep_fr, next_dep_fr;
  or_fr_ptr chain_or_fr, top_or_fr, next_or_fr;
  susp_fr_ptr susp_fr, next_susp_fr;
  qg_sol_fr_ptr solutions, aux_solutions;

  if (YOUNGER_CP(Get_LOCAL_top_cp(), B_FZ)) {
    /* the current node is a generator node without younger consumer **
    ** nodes --> we only have the current node to complete           */
    sg_fr_ptr top_sg_fr;

    /* complete subgoals */
#ifdef DETERMINISTIC_TABLING
    if (IS_DET_GEN_CP(Get_LOCAL_top_cp()))
      top_sg_fr = SgFr_next(DET_GEN_CP(Get_LOCAL_top_cp())->cp_sg_fr);
    else
#endif /* DETERMINISTIC_TABLING */
      top_sg_fr = SgFr_next(GEN_CP(Get_LOCAL_top_cp())->cp_sg_fr);
    do {
      mark_as_completed(LOCAL_top_sg_fr);
      LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);
    } while (LOCAL_top_sg_fr != top_sg_fr);

    /* no dependency frames to release */
    chain_dep_fr = NULL;

    /* no need to adjust freeze registers */
  } else {
    /* the current node is a leader node with younger consumer **
    ** nodes ---> we need to complete all dependent subgoals   */

    /* complete subgoals */
    if (DepFr_leader_dep_is_on_stack(LOCAL_top_dep_fr)) {
      while (LOCAL_top_sg_fr && 
             EQUAL_OR_YOUNGER_CP(SgFr_gen_cp(LOCAL_top_sg_fr), Get_LOCAL_top_cp())) {
        mark_as_completed(LOCAL_top_sg_fr);
        LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);
      }
    } else {
      while (LOCAL_top_sg_fr && 
             YOUNGER_CP(SgFr_gen_cp(LOCAL_top_sg_fr), Get_LOCAL_top_cp())) {
        mark_as_completed(LOCAL_top_sg_fr);
        LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);
      }
    }

    /* chain dependency frames to release */
    chain_dep_fr = NULL;
    while (YOUNGER_CP(DepFr_cons_cp(LOCAL_top_dep_fr), Get_LOCAL_top_cp())) {
      LOCK_DEP_FR(LOCAL_top_dep_fr);
      next_dep_fr = DepFr_next(LOCAL_top_dep_fr);
      DepFr_next(LOCAL_top_dep_fr) = chain_dep_fr;
      chain_dep_fr = LOCAL_top_dep_fr;
      LOCAL_top_dep_fr = next_dep_fr;
    }

    /* adjust freeze registers */
    adjust_freeze_registers();
  }

  /* chain or-frames to release */
  chain_or_fr = NULL;
  top_or_fr = Get_LOCAL_top_cp_on_stack()->cp_or_fr;
  while (top_or_fr != LOCAL_top_or_fr) {
    or_fr_ptr next_or_fr_on_stack;
    LOCK_OR_FRAME(top_or_fr);
    susp_fr = OrFr_suspensions(top_or_fr);
    while (susp_fr) {
      complete_suspension_branch(susp_fr, GetOrFr_node(top_or_fr), &chain_or_fr, &chain_dep_fr);
      next_susp_fr = SuspFr_next(susp_fr);
      FREE_SUSPENSION_FRAME(susp_fr);
      susp_fr = next_susp_fr;
    }
    next_or_fr_on_stack = OrFr_next_on_stack(top_or_fr);
    OrFr_next_on_stack(top_or_fr) = chain_or_fr;
    chain_or_fr = top_or_fr;
    top_or_fr = next_or_fr_on_stack;
  }
  LOCK_OR_FRAME(top_or_fr);
  susp_fr = OrFr_suspensions(top_or_fr);
  while (susp_fr) {
    complete_suspension_branch(susp_fr, GetOrFr_node(top_or_fr), &chain_or_fr, &chain_dep_fr);
    next_susp_fr = SuspFr_next(susp_fr);
    FREE_SUSPENSION_FRAME(susp_fr);
    susp_fr = next_susp_fr;
  }
  OrFr_suspensions(top_or_fr) = NULL;
  OrFr_nearest_suspnode(top_or_fr) = top_or_fr;
  UNLOCK_OR_FRAME(top_or_fr);

  /* release dependency frames */
  while (chain_dep_fr) {
    next_dep_fr = DepFr_next(chain_dep_fr);
    FREE_DEPENDENCY_FRAME(chain_dep_fr);
    chain_dep_fr = next_dep_fr;
  }

  /* release or frames */
  solutions = NULL;
  while (chain_or_fr) {
    aux_solutions = OrFr_qg_solutions(chain_or_fr);
    if (aux_solutions) {
      CUT_join_answers_in_an_unique_frame(aux_solutions);
      SolFr_next(aux_solutions) = solutions;
      solutions = aux_solutions;
    }
    next_or_fr = OrFr_next_on_stack(chain_or_fr);
    FREE_OR_FRAME(chain_or_fr);
    chain_or_fr = next_or_fr;
  }
  if (solutions) {
    CUT_join_answers_in_an_unique_frame(solutions);
    SolFr_next(solutions) = OrFr_qg_solutions(LOCAL_top_or_fr);
    OrFr_qg_solutions(LOCAL_top_or_fr) = solutions;
  }

  /* adjust top register */
  Set_LOCAL_top_cp_on_stack( Get_LOCAL_top_cp() );

  return;
}