32static void share_private_nodes(
int worker_q);
35reset_trail(tr_fr_ptr tr_top, tr_fr_ptr trp)
37 register CELL aux_cell;
40 while (tr_top != trp) {
41 aux_cell = TrailTerm(--trp);
43 if (IsVarTerm(aux_cell)) {
46 if (Unsigned((Int)(aux_cell)-(Int)(H_FZ)) >
47 Unsigned((Int)(B_FZ)-(Int)(H_FZ))) {
48 RESET_VARIABLE(STACK_TO_SBA(aux_cell));
50 RESET_VARIABLE(aux_cell);
53 else if (IsPairTerm(aux_cell)) {
55 if ((ADDR) RepPair(aux_cell) > HeapTop) {
56 trp = (tr_fr_ptr) RepPair(aux_cell);
58#ifdef MULTI_ASSIGNMENT_VARIABLES
60 CELL *aux_ptr = RepAppl(aux_cell);
62 if (Unsigned((Int)(aux_ptr)-(Int)(H_FZ)) >
63 Unsigned((Int)(B_FZ)-(Int)(H_FZ))) {
64 *STACK_TO_SBA(aux_ptr) = TrailTerm(trp);
66 *aux_ptr = TrailTerm(trp);
78#define COMPUTE_SEGMENTS_TO_COPY_TO(Q) \
79 REMOTE_end_local_copy(Q) = (CELL) (REMOTE_top_cp(Q)); \
80 REMOTE_start_local_copy(Q) = (CELL) (B)
88void make_root_choice_point(
void) {
90 LOCAL_top_cp = GLOBAL_root_cp = OrFr_node(GLOBAL_root_or_fr) = B;
93 B->cp_or_fr = GLOBAL_root_or_fr;
95 B = LOCAL_top_cp = GLOBAL_root_cp;
98 LOCAL_top_or_fr = GLOBAL_root_or_fr;
100 LOCAL_prune_request = NULL;
101 BRANCH(worker_id, 0) = 0;
102 H_FZ = (CELL *) LOCAL_GlobalBase;
104 TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
108void free_root_choice_point(
void) {
109 reset_trail(LOCAL_top_cp->cp_tr, TR);
110 TR = LOCAL_top_cp->cp_tr;
111 B = LOCAL_top_cp->cp_b;
112 LOCAL_top_cp = (
choiceptr) LOCAL_LocalBase;
113 H_FZ = (CELL *) LOCAL_GlobalBase;
115 TR_FZ = (tr_fr_ptr) LOCAL_TrailBase;
119void p_share_work(
void) {
120 int worker_q = LOCAL_share_request;
122 if (! BITMAP_member(OrFr_members(REMOTE_top_or_fr(worker_q)), worker_id) ||
123 B == REMOTE_top_cp(worker_q) ||
124 (LOCAL_load <= GLOBAL_delayed_release_load && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
126 REMOTE_reply_signal(LOCAL_share_request) = no_sharing;
127 LOCAL_share_request = MAX_WORKERS;
128 PUT_OUT_REQUESTABLE(worker_id);
133 COMPUTE_SEGMENTS_TO_COPY_TO(worker_q);
134 share_private_nodes(worker_q);
135 REMOTE_reply_signal(worker_q) = sharing;
138 LOCAL_share_request = MAX_WORKERS;
139 PUT_IN_REQUESTABLE(worker_id);
145int q_share_work(
int worker_p) {
146 register tr_fr_ptr aux_tr;
147 register CELL aux_cell;
149 LOCK_OR_FRAME(LOCAL_top_or_fr);
150 if (Get_REMOTE_prune_request(worker_p)) {
152 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
155 YAPOR_ERROR_CHECKING(q_share_work, 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));
157 BRANCH(worker_id, OrFr_depth(LOCAL_top_or_fr)) = BRANCH(worker_p, OrFr_depth(LOCAL_top_or_fr));
158 LOCAL_prune_request = NULL;
159 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
161 reset_trail(LOCAL_top_cp->cp_tr, TR);
162 TR = LOCAL_top_cp->cp_tr;
165 LOCK_WORKER(worker_p);
166 if (BITMAP_member(GLOBAL_bm_idle_workers, worker_p) ||
167 REMOTE_share_request(worker_p) != MAX_WORKERS) {
169 UNLOCK_WORKER(worker_p);
172 REMOTE_share_request(worker_p) = worker_id;
173 UNLOCK_WORKER(worker_p);
176 while (LOCAL_reply_signal == worker_ready);
177 if (LOCAL_reply_signal == no_sharing) {
179 LOCAL_reply_signal = worker_ready;
184 TR = ((
choiceptr)LOCAL_end_local_copy)->cp_tr;
185 aux_tr = ((
choiceptr) LOCAL_start_local_copy)->cp_tr;
186 NEW_MAHASH((ma_h_inner_struct *)HR);
187 while (TR != aux_tr) {
188 aux_cell = TrailTerm(--aux_tr);
189 if (IsVarTerm(aux_cell)) {
190 CELL *ptr = STACK_TO_SBA(aux_cell);
191 *ptr = TrailVal(aux_tr);
192 }
else if ((ADDR) RepPair(aux_cell) >= HeapTop) {
194 aux_tr = (tr_fr_ptr) RepPair(aux_cell);
195#ifdef MULTI_ASSIGNMENT_VARIABLES
196 }
else if (IsApplTerm(aux_cell)) {
197 CELL *cell_ptr = RepAppl(aux_cell);
198 if (!lookup_ma_var(cell_ptr)) {
200 CELL *ptr = STACK_TO_SBA(cell_ptr);
201 *ptr = TrailVal(aux_tr);
211 LOCAL_reply_signal = worker_ready;
212 PUT_IN_REQUESTABLE(worker_id);
213 TR = LOCAL_top_cp->cp_tr;
224void share_private_nodes(
int worker_q) {
231 previous_or_frame = NULL;
232 depth = OrFr_depth(LOCAL_top_or_fr);
234 while (AuxB != LOCAL_top_cp) {
239 OrFr_alternative(
or_frame) = AuxB->cp_ap;
240 OrFr_pend_prune_cp(
or_frame) = NULL;
241 OrFr_nearest_leftnode(
or_frame) = LOCAL_top_or_fr;
243 BITMAP_clear(OrFr_members(
or_frame));
244 BITMAP_insert(OrFr_members(
or_frame), worker_id);
245 BITMAP_insert(OrFr_members(
or_frame), worker_q);
246 if (AuxB->cp_ap && YAMOP_SEQ(AuxB->cp_ap)) {
247 AuxB->cp_ap = GETWORK_SEQ;
249 AuxB->cp_ap = GETWORK;
253 if (previous_or_frame) {
254 OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) =
or_frame;
260 if (previous_or_frame) {
261 OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) =
or_frame;
264 if (depth >= MAX_BRANCH_DEPTH)
265 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"maximum depth exceded (share_private_nodes)");
268 while (
or_frame != LOCAL_top_or_fr) {
276 BRANCH(worker_id, depth) = BRANCH(worker_q, depth) =
branch;
281 while (
or_frame != REMOTE_top_or_fr(worker_q)) {
283 BRANCH(worker_q, OrFr_depth(
or_frame)) = BRANCH(worker_id, OrFr_depth(
or_frame));
284 BITMAP_insert(OrFr_members(
or_frame), worker_q);
290 tr_fr_ptr top, tr_ptr;
291 top = LOCAL_top_cp->cp_tr;
293 while (tr_ptr != top) {
294 CELL aux_cell = TrailTerm(--tr_ptr);
295 if (IsVarTerm(aux_cell) &&
296 ((CELL *)aux_cell < B->cp_h || (
choiceptr)aux_cell > B) &&
297 !((CELL *)aux_cell < H_FZ || (
choiceptr)aux_cell > B_FZ)) {
298 CELL *ptr = STACK_TO_SBA(aux_cell);
299 *ptr = TrailVal(tr_ptr);
300 *(CELL *)aux_cell = (CELL)ptr;
301 }
else if (IsPairTerm(aux_cell) && (ADDR) RepPair(aux_cell) > HeapTop) {
303 aux_cell = (CELL) RepPair(aux_cell);
304 tr_ptr = (tr_fr_ptr) aux_cell;
305#ifdef MULTI_ASSIGNMENT_VARIABLES
307 CELL *cell_ptr = RepAppl(aux_cell);
309 if ((cell_ptr < B->cp_h || cell_ptr > (CELL *)B) && !(cell_ptr < H_FZ || (
choiceptr)cell_ptr > B_FZ)) {
310 CELL *ptr = STACK_TO_SBA(cell_ptr);
312 if ((CELL)ptr != *cell_ptr) {
313 *ptr = TrailVal(tr_ptr);
314 *cell_ptr = (CELL)ptr;
328 REMOTE_top_cp(worker_q) = LOCAL_top_cp = B;
329 REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr = LOCAL_top_cp->cp_or_fr;
331 if (LOCAL_prune_request) {
332 CUT_send_prune_request(worker_q, LOCAL_prune_request);
335 REMOTE_load(worker_q) = LOCAL_load = 0;