From 995e8f6dc71830de1956d1a70d08f73918bce3bf Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 27 Jan 2010 11:01:28 +0000 Subject: [PATCH] fix cut handling with threads do not compile or.threadengine unless yapor on. --- OPTYap/opt.init.c | 2 +- OPTYap/opt.preds.c | 2 +- OPTYap/opt.structs.h | 20 +++++++++++++++++++- OPTYap/or.cowengine.c | 2 +- OPTYap/or.cut.c | 8 ++++---- OPTYap/or.engine.c | 4 ++-- OPTYap/or.macros.h | 12 ++++++------ OPTYap/or.sbaengine.c | 2 +- OPTYap/or.scheduler.c | 20 ++++++++++---------- OPTYap/or.threadengine.c | 12 ++++++------ OPTYap/tab.insts.i | 8 ++++---- 11 files changed, 55 insertions(+), 37 deletions(-) diff --git a/OPTYap/opt.init.c b/OPTYap/opt.init.c index 6a8508e32..7648877d5 100644 --- a/OPTYap/opt.init.c +++ b/OPTYap/opt.init.c @@ -184,7 +184,7 @@ void Yap_init_local(void) { #ifdef ENV_COPY INIT_LOCK(LOCAL_lock_signals); #endif /* ENV_COPY */ - LOCAL_prune_request = NULL; + Set_LOCAL_prune_request(NULL); #endif /* YAPOR */ INIT_LOCK(LOCAL_lock); #ifdef TABLING diff --git a/OPTYap/opt.preds.c b/OPTYap/opt.preds.c index bbe12ebfb..96c15ae61 100644 --- a/OPTYap/opt.preds.c +++ b/OPTYap/opt.preds.c @@ -402,7 +402,7 @@ Int p_parallel_new_answer(void) { AnsFr_next(actual_answer) = NULL; leftmost_or_fr = CUT_leftmost_or_frame(); LOCK_OR_FRAME(leftmost_or_fr); - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { UNLOCK_OR_FRAME(leftmost_or_fr); FREE_QG_ANSWER_FRAME(actual_answer); } else { diff --git a/OPTYap/opt.structs.h b/OPTYap/opt.structs.h index 8446c4d52..583b9a725 100644 --- a/OPTYap/opt.structs.h +++ b/OPTYap/opt.structs.h @@ -324,7 +324,11 @@ struct local_data{ choiceptr top_choice_point; #endif struct or_frame *top_or_frame; - choiceptr prune_request; +#if THREADS + Int prune_request_offset; +#else + choiceptr prune_request_offset; +#endif volatile int share_request; struct local_signals share_signals; volatile struct { @@ -365,7 +369,14 @@ extern struct local_data *LOCAL; #define Set_LOCAL_top_cp(cpt) (LOCAL->top_choice_point = cpt) #endif #define LOCAL_top_or_fr (LOCAL->top_or_frame) +#if THREADS +#define Get_LOCAL_prune_request() offset_to_cptr(LOCAL->prune_request_offset) +#define Set_LOCAL_prune_request(cpt) (LOCAL->prune_request_offset = cptr_to_offset(cpt)) +#else #define LOCAL_prune_request (LOCAL->prune_request) +#define Get_LOCAL_prune_request() (LOCAL->prune_request) +#define Set_LOCAL_prune_request(cpt) (LOCAL->prune_request = cpt) +#endif #define LOCAL_share_request (LOCAL->share_request) #define LOCAL_reply_signal (LOCAL->share_signals.reply) #define LOCAL_p_fase_signal (LOCAL->share_signals.P_fase) @@ -401,7 +412,14 @@ extern struct local_data *LOCAL; #define Set_REMOTE_top_cp(worker, bptr) (REMOTE[worker].top_choice_point = (bptr)) #endif #define REMOTE_top_or_fr(worker) (REMOTE[worker].top_or_frame) +#if THREADS +#define Get_REMOTE_prune_request(worker) offset_to_cptr(REMOTE[worker].prune_request_offset) +#define Set_REMOTE_prune_request(worker,cp) (REMOTE[worker].prune_request_offset = cptr_to_offset(cp)) +#else #define REMOTE_prune_request(worker) (REMOTE[worker].prune_request) +#define Get_REMOTE_prune_request(worker) (REMOTE[worker].prune_request) +#define Set_REMOTE_prune_request(worker,cp) (REMOTE[worker].prune_request = cp) +#endif #define REMOTE_share_request(worker) (REMOTE[worker].share_request) #define REMOTE_reply_signal(worker) (REMOTE[worker].share_signals.reply) #define REMOTE_p_fase_signal(worker) (REMOTE[worker].share_signals.P_fase) diff --git a/OPTYap/or.cowengine.c b/OPTYap/or.cowengine.c index e486399dd..3ac324071 100644 --- a/OPTYap/or.cowengine.c +++ b/OPTYap/or.cowengine.c @@ -120,7 +120,7 @@ int p_share_work(void) { int q_share_work(int worker_p) { LOCK_OR_FRAME(LOCAL_top_or_fr); - if (REMOTE_prune_request(worker_p)) { + if (Get_REMOTE_prune_request(worker_p)) { /* worker p with prune request */ UNLOCK_OR_FRAME(LOCAL_top_or_fr); return FALSE; diff --git a/OPTYap/or.cut.c b/OPTYap/or.cut.c index 5f701c0f3..9fb4dfba0 100644 --- a/OPTYap/or.cut.c +++ b/OPTYap/or.cut.c @@ -102,14 +102,14 @@ void prune_shared_branch(choiceptr prune_cp) { } while (Get_LOCAL_top_cp() != prune_cp); #ifdef YAPOR_ERRORS - if (LOCAL_prune_request && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, LOCAL_top_cp)) + if (Get_LOCAL_prune_request() && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, LOCAL_top_cp)) YAPOR_ERROR_MESSAGE("EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, LOCAL_top_cp) (prune_shared_branch)"); #endif /* YAPOR_ERRORS */ /* store answers not pruned */ if (qg_solutions) CUT_join_answers_in_an_unique_frame(qg_solutions); LOCK_OR_FRAME(leftmost_or_fr); - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { UNLOCK_OR_FRAME(leftmost_or_fr); if (qg_solutions) CUT_free_solution_frame(qg_solutions); @@ -192,14 +192,14 @@ void prune_shared_branch(choiceptr prune_cp) { } #ifdef YAPOR_ERRORS - if (LOCAL_prune_request && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp())) + if (Get_LOCAL_prune_request() && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp())) YAPOR_ERROR_MESSAGE("EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp()) (prune_shared_branch)"); #endif /* YAPOR_ERRORS */ /* store answers not pruned */ if (qg_solutions) CUT_join_answers_in_an_unique_frame(qg_solutions); LOCK_OR_FRAME(leftmost_or_fr); - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { UNLOCK_OR_FRAME(leftmost_or_fr); if (qg_solutions) CUT_free_solution_frame(qg_solutions); diff --git a/OPTYap/or.engine.c b/OPTYap/or.engine.c index a8bfe6a77..a61532486 100644 --- a/OPTYap/or.engine.c +++ b/OPTYap/or.engine.c @@ -94,7 +94,7 @@ void make_root_choice_point(void) { B->cp_or_fr = GLOBAL_root_or_fr; LOCAL_top_or_fr = GLOBAL_root_or_fr; LOCAL_load = 0; - LOCAL_prune_request = NULL; + Set_LOCAL_prune_request(NULL); BRANCH(worker_id, 0) = 0; #ifdef TABLING_INNER_CUTS LOCAL_pruning_scope = NULL; @@ -196,7 +196,7 @@ int q_share_work(int worker_p) { #endif /* YAPOR_ERRORS */ /* there is no pending prune with worker p at right --> safe move to worker p branch */ BRANCH(worker_id, OrFr_depth(LOCAL_top_or_fr)) = BRANCH(worker_p, OrFr_depth(LOCAL_top_or_fr)); - LOCAL_prune_request = NULL; + SetLOCAL_prune_request = NULL; UNLOCK_OR_FRAME(LOCAL_top_or_fr); /* unbind variables */ diff --git a/OPTYap/or.macros.h b/OPTYap/or.macros.h index 2329be1ff..7d51a9857 100644 --- a/OPTYap/or.macros.h +++ b/OPTYap/or.macros.h @@ -129,7 +129,7 @@ STD_PROTO(static inline qg_sol_fr_ptr CUT_prune_solution_frames, (qg_sol_fr_ptr, goto shared_end #define SCH_check_prune_request() \ - if (LOCAL_prune_request) { \ + if (Get_LOCAL_prune_request()) { \ SCHEDULER_GET_WORK(); \ } @@ -167,7 +167,7 @@ STD_PROTO(static inline qg_sol_fr_ptr CUT_prune_solution_frames, (qg_sol_fr_ptr, #define CUT_prune_to(PRUNE_CP) \ if (YOUNGER_CP(Get_LOCAL_top_cp(), PRUNE_CP)) { \ - if (! LOCAL_prune_request) \ + if (! Get_LOCAL_prune_request()) \ prune_shared_branch(PRUNE_CP); \ PRUNE_CP = Get_LOCAL_top_cp(); \ } @@ -342,8 +342,8 @@ static inline void CUT_send_prune_request(int worker, choiceptr prune_cp) { LOCK_WORKER(worker); if (YOUNGER_CP(REMOTE_top_cp(worker), prune_cp) && - (! REMOTE_prune_request(worker) || YOUNGER_CP(REMOTE_prune_request(worker), prune_cp))) - REMOTE_prune_request(worker) = prune_cp; + (! Get_REMOTE_prune_request(worker) || YOUNGER_CP(Get_REMOTE_prune_request(worker), prune_cp))) + Set_REMOTE_prune_request(worker, prune_cp); UNLOCK_WORKER(worker); return; } @@ -352,8 +352,8 @@ void CUT_send_prune_request(int worker, choiceptr prune_cp) { static inline void CUT_reset_prune_request(void) { LOCK_WORKER(worker_id); - if (LOCAL_prune_request && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp())) - LOCAL_prune_request = NULL; + if (Get_LOCAL_prune_request() && EQUAL_OR_YOUNGER_CP(Get_LOCAL_prune_request(), Get_LOCAL_top_cp())) + Set_LOCAL_prune_request(NULL); UNLOCK_WORKER(worker_id); return; } diff --git a/OPTYap/or.sbaengine.c b/OPTYap/or.sbaengine.c index b57d602b2..28dc49391 100644 --- a/OPTYap/or.sbaengine.c +++ b/OPTYap/or.sbaengine.c @@ -151,7 +151,7 @@ int q_share_work(int worker_p) { register CELL aux_cell; LOCK_OR_FRAME(LOCAL_top_or_fr); - if (REMOTE_prune_request(worker_p)) { + if (Get_REMOTE_prune_request(worker_p)) { /* worker p with prune request */ UNLOCK_OR_FRAME(LOCAL_top_or_fr); return FALSE; diff --git a/OPTYap/or.scheduler.c b/OPTYap/or.scheduler.c index 392bfddea..0132adedd 100644 --- a/OPTYap/or.scheduler.c +++ b/OPTYap/or.scheduler.c @@ -99,7 +99,7 @@ void PUT_OUT_ROOT_NODE(int worker_num) { static inline void move_up_to_prune_request(void) { #ifdef YAPOR_ERRORS - if (EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp())) + if (EQUAL_OR_YOUNGER_CP(Get_LOCAL_prune_request(), Get_LOCAL_top_cp())) YAPOR_ERROR_MESSAGE("invalid LOCAL_prune_request (move_up_to_prune_request)"); #endif /* YAPOR_ERRORS */ @@ -123,7 +123,7 @@ void move_up_to_prune_request(void) { UNLOCK_OR_FRAME(LOCAL_top_or_fr); } SCH_update_local_or_tops(); - } while (Get_LOCAL_top_cp() != LOCAL_prune_request); + } while (Get_LOCAL_top_cp() != Get_LOCAL_prune_request()); CUT_reset_prune_request(); #ifdef TABLING @@ -153,7 +153,7 @@ int get_work(void) { LOCAL_load = 0; /* check for prune request */ - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) move_up_to_prune_request(); /* find nearest node with available work */ @@ -267,7 +267,7 @@ int get_work(void) { static int move_up_one_node(or_fr_ptr nearest_livenode) { #ifdef YAPOR_ERRORS - if (LOCAL_prune_request && EQUAL_OR_YOUNGER_CP(LOCAL_prune_request, Get_LOCAL_top_cp())) + if (Get_LOCAL_prune_request() && EQUAL_OR_YOUNGER_CP(Get_LOCAL_prune_request(), Get_LOCAL_top_cp())) YAPOR_ERROR_MESSAGE("invalid LOCAL_prune_request (move_up_one_node)"); #endif /* YAPOR_ERRORS */ @@ -286,7 +286,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { /* pending prune ? */ if (OrFr_pend_prune_cp(LOCAL_top_or_fr) - && ! LOCAL_prune_request + && ! Get_LOCAL_prune_request() && CUT_last_worker_left_pending_prune(LOCAL_top_or_fr)) { #ifdef TABLING choiceptr aux_cp = Get_LOCAL_top_cp(); @@ -351,7 +351,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { update_local_tops1: #endif /* TABLING_INNER_CUTS */ SCH_update_local_or_tops(); - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); return TRUE; } @@ -420,7 +420,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { update_local_tops2: #endif /* TABLING_INNER_CUTS */ SCH_update_local_or_tops(); - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); return TRUE; } @@ -453,7 +453,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { /* last member worker in node ? */ if (BITMAP_alone(OrFr_members(LOCAL_top_or_fr), worker_id)) { #endif /* TABLING */ - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { CUT_free_solution_frames(OrFr_qg_solutions(LOCAL_top_or_fr)); #ifdef TABLING_INNER_CUTS CUT_free_tg_solution_frames(OrFr_tg_solutions(LOCAL_top_or_fr)); @@ -512,7 +512,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { or_fr_ptr leftmost_until; tg_solutions = OrFr_tg_solutions(LOCAL_top_or_fr); leftmost_until = CUT_leftmost_until(LOCAL_top_or_fr, OrFr_depth(TgSolFr_gen_cp(tg_solutions)->cp_or_fr)); - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); OrFr_tg_solutions(LOCAL_top_or_fr) = NULL; UNLOCK_OR_FRAME(LOCAL_top_or_fr); @@ -526,7 +526,7 @@ int move_up_one_node(or_fr_ptr nearest_livenode) { goto update_local_tops3; } #endif /* TABLING_INNER_CUTS */ - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); } #endif /* TABLING */ diff --git a/OPTYap/or.threadengine.c b/OPTYap/or.threadengine.c index 2f346f3a0..c9adcd6c1 100644 --- a/OPTYap/or.threadengine.c +++ b/OPTYap/or.threadengine.c @@ -14,7 +14,7 @@ ** ------------------ */ #include "Yap.h" -#ifdef THREADS +#if defined(THREADS) && defined(YAPOR) #ifdef HAVE_STRING_H #include #endif /* HAVE_STRING_H */ @@ -60,7 +60,7 @@ void make_root_choice_point(void) { B->cp_or_fr = GLOBAL_root_or_fr; LOCAL_top_or_fr = GLOBAL_root_or_fr; LOCAL_load = 0; - LOCAL_prune_request = NULL; + Set_LOCAL_prune_request(NULL); BRANCH(worker_id, 0) = 0; #ifdef TABLING_INNER_CUTS LOCAL_pruning_scope = NULL; @@ -118,7 +118,7 @@ int p_share_work(void) { int q_share_work(int worker_p) { LOCK_OR_FRAME(LOCAL_top_or_fr); - if (REMOTE_prune_request(worker_p)) { + if (Get_REMOTE_prune_request(worker_p)) { /* worker p with prune request */ UNLOCK_OR_FRAME(LOCAL_top_or_fr); return FALSE; @@ -130,7 +130,7 @@ int q_share_work(int worker_p) { #endif /* YAPOR_ERRORS */ /* there is no pending prune with worker p at right --> safe move to worker p branch */ BRANCH(worker_id, OrFr_depth(LOCAL_top_or_fr)) = BRANCH(worker_p, OrFr_depth(LOCAL_top_or_fr)); - LOCAL_prune_request = NULL; + Set_LOCAL_prune_request(NULL); UNLOCK_OR_FRAME(LOCAL_top_or_fr); #ifdef OPTYAP_ERRORS @@ -546,8 +546,8 @@ void share_private_nodes(int worker_q) { #endif /* TABLING_INNER_CUTS */ /* update worker Q prune request */ - if (LOCAL_prune_request) { - CUT_send_prune_request(worker_q, LOCAL_prune_request); + if (Get_LOCAL_prune_request()) { + CUT_send_prune_request(worker_q, Get_LOCAL_prune_request()); } /* update load and return */ diff --git a/OPTYap/tab.insts.i b/OPTYap/tab.insts.i index 6efd5cc88..79ba06aea 100644 --- a/OPTYap/tab.insts.i +++ b/OPTYap/tab.insts.i @@ -888,7 +888,7 @@ UNLOCK_TABLE(ans_node); #endif /* TABLE_LOCK_LEVEL */ LOCK_OR_FRAME(leftmost_or_fr); - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { UNLOCK_OR_FRAME(leftmost_or_fr); SCHEDULER_GET_WORK(); } else { @@ -972,7 +972,7 @@ } /* check for prune requests */ - if (LOCAL_prune_request) { + if (Get_LOCAL_prune_request()) { #if defined(TABLE_LOCK_AT_ENTRY_LEVEL) UNLOCK(SgFr_lock(sg_fr)); #elif defined(TABLE_LOCK_AT_NODE_LEVEL) @@ -1200,7 +1200,7 @@ end_or_fr = OrFr_next(end_or_fr); } } while (start_or_fr != end_or_fr); - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); } #endif /* YAPOR */ @@ -1285,7 +1285,7 @@ #endif /* TABLING_INNER_CUTS */ start_or_fr = OrFr_next(start_or_fr); } - if (LOCAL_prune_request) + if (Get_LOCAL_prune_request()) pruning_over_tabling_data_structures(); } }